A very convenient function for this is implemented in Bozhidar Batsov's excellent crux package.
crux
https://github.com/bbatsov/crux
After installing (from melpa or melpa-stable) use crux-sudo-edit. Also useful is crux-reopen-as-root.
crux-sudo-edit
crux-reopen-as-root