"Deauthorize your computer from iTunes, if applicable.
Back up your data using Time Machine or other backup methods for OS X Mavericks or Mountain Lion.
If you use Find My Mac or other iCloud features on this Mac, complete these steps:
Back up your iCloud content.
Choose Apple Menu () > System Preferences, then click iCloud.
Deselect the Find My Mac checkbox.
Sign out of iCloud. When you sign out of iCloud, you're asked whether you want to remove iCloud data from your Mac. Removing iCloud data in this way makes sure that the data isn't also removed from any of your other devices that are using the same iCloud account.
If you're using OS X Mountain Lion v10.8 or later, sign out of iMessage:
In the Messages app, choose Preferences > Accounts.
Select your iMessage account, then click Sign Out.
Reformat your hard drive and reinstall OS X. Follow the appropriate instructions:
OS X Mavericks
OS X Mountain Lion
OS X Lion
After you reformat your hard drive and reinstall OS X, the computer restarts to a Welcome screen and asks you to choose a country or region. If you want to leave the Mac in an out-of-box state, don't continue with the setup of your system. Instead, press Command-Q to shut down the Mac. When the new owner turns on the Mac, the Setup Assistant will guide them through the setup process."
Apple has a guide on “how to back up and remove data from your Mac before selling or giving the computer away.” Basically, you need to deauthorize your Mac from iTunes, back up your data and iCloud content, sign out of iMessage, reformat your hard drive and reinstall OS X. You can find complete instructions here: http://support.apple.com/en-us/HT201065