How to reset iMac to factory defaults?
Based on this answer and personal experience with a Yosemite iMac I recommend


Hold ⌘+R during boot to boot to recovery console.
Use Disk tool to erase main partition.
Exit disk tool, launch system reinstallation instead.


I was very surprised that skipping step 2 I ended up with a fresh install which nevertheless contained the account I had on the machine before. Not factory default.

The disk erase step allows choosing the tradeoff between speed and security. So if you have personal data on the machine, better do a slow but thorough erase there.