Yes, it won't hurt the iMac. In fact they can even be used sideways, as long as you don't block any vents. Hard drive bearings are said to last longest when they are either upright or flat, but apart from the convection-cooled Mac Cube I don't know of any Mac that depends on orientation for cooling or anything else.
If you are putting them away for any length of time, get some silica gel packets or a "Thirsty Hippo" or local equivalent to ensure humidity does not speed corrosion or otherwise damage your machines. Wrap them tightly in plastic to prevent critters crawling in, there is nothing worse than finding something living in your old computer. Dead bodies or other debris may be corrosive or conductive. If your iMac is the CRT kind consider cutting a panel out of plywood to protect the glass screen. CRTs are hard to smash but easy to scratch or chip.
If you are putting away anything really precious (iMac signed by the Steves?) best practice is sealing the computer in an environment of dry nitrogen gas - it's a serious measure but not actually that hard to do since airtight bags are easy to find and nitrogen is becoming common in auto tire shops. Removing oxygen prevents oxidisation (rust) and will also make it impossible for creatures to colonise your Mac since they cannot live without oxygen.
In the last decade the ROHS directive has seen the use of lead-free solder increase. One big problem with this is the growth of "whiskers" from the solder and other circuit elements that can bridge what should be gaps between circuit paths. While the exact cause of whiskers and the right way to prevent their growth post-manufacturing is still unknown there are minority suggestions that vacuum or nitrogen environments help - but from my reading, a temperature-controlled or even cycling environment is more likely to be effective. When the exact facts are known the right way to store computers long-term will probably change. But it's sad to think that there is a risk to our machines even if they are well cared-for. Modern Apple machines, since about 2006, conform to the ROHS directive so this applies to them. Older machines may well be manufactured using lead solder and so tin whiskers would not be an issue. I could not find a definitive answer.