A simple solution would write an AutoIt program that attempts to ping your internet service provider's DNS resolver. This is the only true way to detect if you're "connected" to the internet or not, since it's not always reliable to ping third party websites.
I would set it up to ping every minute, and if no response is received for 5 minutes, shut the computer down (or set it to go to sleep mode). Fortunately, AutoIt has a built-in
The simple script would look like the following:
Local $i = 0
While $i < 5 ; Looping until we hit 5 attempts...
If Ping("126.96.36.199", 10000) == 0 Then ; If we couldn't ping...
$i = $i + 1 ; Increment the counter.
Else ; Else, if we could,
$i = 0 ; Reset the counter.
Sleep(60000) ; Finally, loop every minute.
; If the script gets here, we missed 5 pings - take action.
Shutdown(32) ; See the Shutdown() documentation, this makes the PC sleep.
Before you run the computer overnight, you could then just execute the above script. To continue using your computer normally, simply close the script.
Disclaimer: I have not tested this code (I wrote it quickly in Notepad++), but it looks viable.