The phone has to "stay awake" to keep a connection with the IM server. Allowing it to "sleep" would drop the connection, showing you offline. Both gtalk and aim support push, so I think thats how they keep alive without killing your battery.
What messaging service do you need to connect to?