Hi, though Apple lists 2 GB as minimal RAM, that's laughable, 6 GB on my iMac is still not enough.
Open Activity Monitor, Show:>All Processes, sort on CPU%, see if anything using too much CPU% when this happens, click on Memory tab, do you have many Pageouts?
Open Console in Utilities & see if there are any clues or repeating messages when this happens.
Also, open console in Applications>Utilities, check the system log for the date/time of the last problem for clues.
BDAqua is spot on, your iMac is starving for RAM. I would recommend upgrading to 12 or 16 GB of RAM. You can buy very high quality RAM from dependable vendor such as OWC (www.macsales.com) or Crucial for as low as $50 to get it to 12GB. To upgrade to 16GB that will be closer to $100 and is something you can do at a later date.