State: wifi connected
Net -> Wifi -> set off IF %SCREEN off
Net ->Wifi -> set on IF %SCREEN on
you can do the same for mobile data if that's what you're after
edit: haven't tested or tried this, just off the top of my head
I think it's a little more complicated than that. It should turn off wifi when the screen goes off without an issue, but once that happens, the "wifi connected" context is no longer true. Once that happens, the "set on IF %SCREEN on" can never happen because wifi is no longer connected. I would try something like this:
Profile 1:
Context: Wifi connected
Task: Variable Set %WifiOn to 1
Exit Task: Variable subtract %WifiOn by 1
Profile 2:
Context: State->Varbiable Value %WifiOn = 1
Context: Event->Display Off
Task: Wifi off
Task: Variable Set %WifiDisplay = 1
Profile 3:
Context: State->Variable Value %WifiDisplay = 1
Context: Event->Dislpay On
Task: Wifi on
You may or may not need that third profile. Tasker will revert changes that it made when entering a profile once it exits the profile, but I'm not positive with the event context. Also, this might be possible with fewer profiles, but the concept is the same. EDIT - ignore this, it made sense with my original profiles before I edited it.
EDIT: wait, there might be a problem with this, let me go through it again.
EDIT2: Okay, revised it. It should do what you want, with one issue - If you are connected to wifi, turn the screen off, then leave wifi range, when you turn the screen back on, wifi will turn back on, and stay on. What you could do is add more tasks to the third profile that sleeps for a few seconds, then shuts off wifi if it can't connect.