HTC One M8 overheating, random reboots and unable to power it off
For a quick fix for it rebooting after you power off, try holding the volume-up button while holding the power button. For the phone, it simulates a battery pull.

Maybe try to wait overnight and wait until the morning to see if the problem still persists. If it does, hold the volume-down button and the power button at the same time, from the shutdown state to enter the Hboot HTC bootloader.

If you have a custom recovery installed, enter it and try to clear the cache and dalvik-cache partitions. If you don't have a custom recovery, use the fastboot command: fastboot erase cache with a simple tool like Minimal ADB and Fastboot while in fastboot in the bootloader.

If this still doesn't work, you're probably going to have to factory reset/format the whole system.

I have an HTC One M8 (writing on it right now), and the only time this happens is when I flash a corrupt ROM, however.

If you're going to have to format it, I suggest flashing the stock Android ROM, it has really nice animations.