Here's the basic instructions: Unlock your mobile wireless device
It's pretty quick if you're a current T-Mobile customer. It becomes complicated if you are not currently a customer or never were one.
After the unlock is approved, you'll need to sync the phone in iTunes to complete the process.
Manage your T-Mobile account