Due to the wiring, it might be better to leave the wheel mounted, but do not turn the bike upside down! You will damage stuff.
There are special bike stands which can help in holding the rear wheel up for easy working. Generally they cost around 30 UK Pounds, for a cheap one from Aldi or similar.
This Guy is using one:-
If you have to remove the rear wheel, remember it must be cleaned where the nuts mount, either side of the chain stays, and the nuts and washers too, no grease or oil when you put it back together. It might "slip!"
Correct torque is also needed, and maybe a torque lock bracket (maybe wrong name!) added.
This is to help prevent the motor turning in the chain stays and ripping all the wiring out of the motor....difficult repair sometimes I am told!!!
Then you have to adjust the inner/outer nuts, to have full tightness, but total freedom for the bearings, no binding!
Which is why many do not take the wheel off!!
regards and I hope this helps.
Andy
PS. Many Youtube videos show the bike upside down, do this at your peril!