This Android application will turn your Wi-Fi off when no application is actively using Wi-Fi for a certain amount of time while the screen is off.
The application takes a wild guess and assumes that if Wi-Fi data transfer rate is less than 64KiB per minute for 15 minutes in a row then it means that there are no applications that actively use Wi-Fi. If Wi-Fi was turned off by the application, the connection will be restored again once the screen is on.
Also, if there's no Wi-Fi connection within 1 minute then this aplication will turn Wi-Fi off too.
For some devices the timings may be slightly different.
Google Play page:
https://play.google.com/store/apps/details?id=net.alkatrazstudio.wifiidletimeout