Have you tried a software restore through itunes?Its always good to do that, that way we can narrow down the problem to a hardware failure. Make sure you back up any sensitive data before the restore because it will wipe the handset.
If you have already done that and it did not work. check your "diagnostics and usage" tab It can be found under general settings on IOS 7.1.2 and below, or under Privacy on IOS 8 and above. See if the device is registering a hardware failure. They register as "Panic.plist" or "Panic.IPS". If you see one of these my friend you are suffering from a hardware failure. If you have any technical experience you could test the screen and the battery. Its possible one of those 2 components are failing. However you should inspect all components for damage. iPhone's can act very weird when they have a damaged component.
If its not something obviously damaged it could get tricky from there because now you have to test the motherboard, which requires removing the shields Apple soldered on and the knowledge to inspect & test the board.