I've tried nearly everything suggested here, and my Wifi still turns off after a period of inactivity. The phone is on Nighttime Saver mode, which stops syncing data after 15 minutes of inactivity during off-peak hours (10 pm-5 am). Supposedly, syncing is supposed to resume when you press any button, but I do get a lot of emails delayed (using Maildroid), because even with data off at night, my Wifi still goes to sleep (even when set to Never Sleep). The Nighttime saver is otherwise supposed to sync without restrictions during peak hours, but in reality, it doesn't. Whenever my phone is idle, when I press a button after a bit, it takes about 2-3 minutes for the data and a bit longer for Wifi to reconnect. Most often, it doesn't do so automatically, so I have to do the Airplane on/off mode to get it going again. I did try setting the battery on Performance mode, but as stated above, it drains the battery even quicker.
The only thing I haven't done is reset the entire phone from scratch...but goodness, what a bother this is turning out to be!
Why does the phone not follow the settings and just randomly connect/disconnect data/Wifi? Very frustrating!