It seems once it takes the mailboxes offline even if you are connected to the internet it will not come back on until you click on mailboxes and specifically tell them to go online again.
How big is your mailbox? If your emails are greater than about 1GB in size, Mail can start behaving quirkily like this. Maybe create a new user account in System preferences, import your emails into it and set it up like the original account and see if it gets the same problems. If it doesn't then we can narrow the problem down to something in your Home folder.
Sorry, I wasn't being very eloquent. Those two things are unrelated but both might be something you want to check out. You can check the size by slicking on one of the folders in Mail and pressing COMMAND-I, then adding the numbers. The second user account creation is to check if you have a bad network setting or a bad preference file relating to Mail.