What happens if you disconnect all of the cables plugged into the USB ports, ethernet port, etc. and see what happens when the ceiling fan turns off. Is the ceiling fan on the same electrical circuit as the iMac? Does it have multiple speeds that you can experiment with to see whether turning it off from a low speed behaves the same as at high speed? Does the fan have a remote control feature, or does it rely on a wall switch?
Have you tried temporarily connecting the iMac to a different electrical circuit in another room using a long extension cord? Are your electrical outlets properly grounded? I would like to rule out whether a voltage drop or other electrical glitch that occurs when you power up the ceiling fan is causing the iMac to think that there is network activity to wake up for, or that a key has been pressed or the mouse bumped. It would be helpful to know what model iMac you have, and whether the mouse and keyboard are connected via cables, or whether they are wireless.
One other experiment to try is to open the System Preferences and look for the Energy Saver settings. Is the 'Wake for network access' option selected? If it is, temporarily uncheck the box and see if that makes any difference.
How long has this issue been occurring? Did it just recently start? Were there any changes made to the electrical wiring right before the issues stared?