I'm posting this as an answer in the hope that this will solve someone elses problems.
Scenario: every time I left my backups to run or downloads running in the background I would leave my machine alone and prevent the machine going to sleep using the Energy Saver settings. I would almost always come back to find the computer turned off and then find that an Software Update had been applied but my backups had been killed and I was either switched off or the machine was back at the login screen having restarted.
I spent a huge amount of time looking through the system logs and tracing events and found that the constant logging out and restarting was down to a setting deep in the system:
System Preferences > Security & Privacy > Privacy > (unlock the lock at the bottom) > Advanced
You will now see a little checkbox called "Logout after 60 mins of inactivity"
It took me weeks to find this, and a lot of sanity and paranoia. I hope this helps someone somewhere!