About Buying AT&T iPhones and then unlocking them later?

Hi..

I have a few questions about this topic.

There are some websites such as ebay and others selling AT&T GSM iPhones. These phones are locked to AT&T, but they're being sold with a clean ESN and stuff.

I want to know if I can buy this AT&T GSM iPhone and then unlock it. Will I be able to use it on overseas carriers without any issues? Any advice on what to look for when buying a model such as this.

Furthermore, how can I unlock the iphone or how much would it cost? I have heard that there are certain ways to do so.

Thanks in advance for the help.