Before checking for viruses, check your power settings. Many computers (laptops especially) are set to hibernate/sleep after a period of inactivity. EDIT: Overheating can also cause a computer to shut down, but you tend to hear the fans getting much louder before that happens.
As for the internet turning on/off... there's a number of possible causes, ranging from WiFi signal dropping to router resetting to damage in an ethernet cable. More details plox.
Oh and of course, check for viruses. Viruses can do many things to be annoying, although sometimes viruses have nothing to do with how a computer/network behaves.