Try reset P-Ran and SMC
keep your system up to date , try see if an EFI update missing ?
Just for testing try create a new user acount , see if new account go to sleep mode in normal way ?
if is possible use an external drive or flash drive with a fresh system installed on it , boot from it and see if problem ocure again ?
need to know ,do you adding or replace ram or harddrive on this imac ?
Try boot from an other system , installed on external drive ?
advanced power save setting ? about spin down hard drive when not used ?
( yes i guess you alraidy done that dozen time )
if is possible try snapshoot your setting an post them ( CMD -SHIFT - 4 ( not use numeric keypad )
for power save - screen saver option -
do you use file vault ? any back ground application ? anti-virus ? task who are specialy launch when sleep mode is activated ?
re-install a totaly new fresh system could be a good idea at this point , BUT do a back up first
no more ideas for now