Hold down D when you start the Mac and run an extended test in the Apple Hardware Test. If you get an error then you know you have a HW fault (although it's not perfect so could still possibly have one even if the test is clean).
If no error then back up data, load to the recovery environment and use Disk Utility to wipe the OS X partition and do a clean install. If that fixes the issue then it was SW, if not then go ahead and contact Apple.
http://support.apple.com/kb/HT1509?viewlocale=en_US&locale=en_US