You know, if you look this is all in the Apple Support area online.
In general, log out of iCloud and disable Find My iPhone. Make sure, there is no data you want that is not backed up. I would recommend doing a backup in iTunes, even if you want to just set up the device freshly.
Download the approapriate Restore image for your device and Option-Click on iTunes with the Restore button. This will show a dialog to select the Restore image. Alternately, just pressing the Restore button will download the current release image and install that, IF YOU ARE NOT RUNNING A LATER BETA VERSION.
You cannot revert the iPhone from current betas to the shipping image, since certain firmware has been updated (most likely modem and secure enclave.)