Did the iMac come with the original install DVD's?
They can be used to boot the iMac, erase the internal drive, and re-install a "fresh copy" of the OS.
Another way to do it is to create a bootable USB flash drive with the OS installer on it.
What you'll need:
- a usb flash drive 8gb in size
- a copy of the OS installer you're going to use
- the free app "DiskMaker X". You'll need to get an older copy from here:
http://diskmakerx.com/whats-this/
Which version you download will depend on which version of the OS you're going to install.
You then erase the USB flash drive to "Mac OS extended with journaling enabled" using Disk Utility.
Then... use DiskMaker to create the bootable flash drive.
IMPORTANT:
Because the iMac is old, you're limited as to which version of the OS will work with it.
I'm guessing you will want:
- 10.6.8 "Snow Leopard"
- 10.7.5 "Lion"
- 10.8 "Mountain Lion"
I'm not sure "how far you can go" insofar as later versions of the OS are concerned.
You may not want the "newest version you can run" -- because newer versions of the OS tend to run SLOWER on older Macs. There is "a balance" to be found here.