To make sure that this is not software related, set it back to factory settings, without using any backup data afterwards, and maybe skip the iCloud part as well. Set up the rest of the personal settings manually and test both devices. Even though it might take a week until you'll get results, this is the only way to find out if this is software related. iTunes will download a new copy of the iOS firmware for each device and use it to set them up.
Since there are different firmware packages for the iPad and the iPhone, the problem must be caused by 3rd party data or settings.
If the devices work longer than they do now without shutting down, restore from the latest backup. If the problem comes back, the backup data contained corrupt data, causing your issues.
If it still does not work correctly, get them checked by Apple or an Apple Authorized Service Provider:
Use iTunes to restore your iOS device to factory settings - Apple Support
Find an Apple Authorized Service Provider
iPhone - Contact Support - Apple Support