First, make sure you are backed up. Contacts can be backed up either through Google or My Contacts Backup. They can also be exported to a file on the memory card, but I have found this to be less than perfectly reliable. App Brain, available in the Market, can back up your downloaded application list. I did it manually, in a NotePad like app on my PC. You will need to know your GMAIL account info too (email address/password).
Once your info is backed up, go to Settings > Privacy, and there you will find Factory Data Reset. Just tap it and follow the prompts. Data on your memory card is NOT wiped, so things like your pics and sound files are OK.
HTH