Hi Greg, sorry to hear about your trouble...
Firstly I would check your immediate area for other devices that might be throwing off signals in the 2.4GH range, which includes; wireless homephones and their base stations, microwaves, mobiles or other wireless devices ect... Vague I know, but if your desk is overcrowded with other antennas or a single powerful antenna, even large metal objects its worth moving them aside just to see.
Secondly, have you tried turning your iMac's Bluetooth off/on via the Bluetooth menu bar dropdown? Or turning your keyboard off/on (assuming you have the aluminum model) press and hold the power button for several seconds until the green light stops shining, release and single press, give it a second to automatically pair.
Thirdly, tried to manually re-pair your keyboard?
Do this by going into Bluetooth Preferences and deleting your keyboard from the device list by selecting it and clicking the - minus, then turning your keyboard off/on the light should now start flashing continuously upon power up. Click on the + at the bottom of the device list. Or from the Bluetooth menu bar icon select "Set Up Bluetooth Device.." you should then see your keyboard listed, the rest is obvious.
Good luck, let me know if any of that helps, or otherwise.