From this article, if you’re using one of the Wifi dongles on a Pi 1 or 2 (Pi3 has built in wifi), you can prevent the random dropouts during periods of inactivity by:
sudo nano /etc/modprobe.d/8192cu.conf
and then paste in and save this:
options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1
and then reboot.