It's been posted on here before but basically I think the general consensus is to do as follows:
Settings -> Messages -> Send & Recieve -> Apple ID -> Sign Out
Settings -> Facetime -> Apple ID -> Sign Out
Settings -> iTunes and App Stores -> Apple ID -> Sign Out
Settings -> iCloud -> Delete Account
Then do the standard erase everything by going to:
Settings -> General -> Reset -> Erase All Content and Settings
you can also go into itunes and unassociate the phone from the account that way. i recently found out about that and realized that my old phones were still in there and unlinked them.