If you see the same thing on both the internal and external displays then that almost completely rules out a problem with your iMac's LCD display. Does the issue show up immediately when you power up the system (eg gray screen with Apple logo), or does the issue wait to appear until after the OS has loaded and you can see the icons start to appear on the desktop? If it occurs even on the initial gray screen then you likely have a hardware issue that will require servicing. If the issue occurs once you've booted then you may have a software issue.
If you boot into Safe Mode do you still see the issue? If not, then it may provide more support that there is a software issue. You can boot into safe mode by holding down the shift key right after you hear the startup tone, and then let go once the gray Apple appears on the display.
http://support.apple.com/kb/HT1455
http://support.apple.com/kb/HT1564
You could also consider reinstalling Mac OS X using the Lion recovery mode:
http://support.apple.com/kb/HT4718