See the following:
Startup programs: Open System Preferences, Users & Groups, highlight your user name, and click on "Login Items". If anything is listed there, click on the small lock at the bottom and enter your admin password. The lock will open. Now highlight anything listed above and press the small minus sign at the bottom. That will remove the startup item or program.
Activity Monitor: You can find it in Applications, Utilities, Activity Monitor.app. When you open the app, it will show you what's running in the background. If something is running in the background it can prevent your iMac from sleeping.