The hardware interface would be the easiest like others were saying. Here is a project someone else shared that does that.
https://www.hackster.io/zvonko-bockaj/wemos-esp8266-remote-pc-switch-062c7a
The wake-on-lan part is easy and here is some code for that.
https://github.com/koen-github/WakeOnLan-ESP8266
I'm also interested in sending some kind of RPC call to a system (linux/windows/mac) via wifi to initiate a shutdown. If I find a solution I will post it here.
UPDATE: I found a Sleep-On-Lan project that should work. You can use the same code above for the ESP8266 but just reverse the MAC Address of the system you want to shutdown.
https://github.com/SR-G/sleep-on-lan
You will need to run this as a service on the system you intend to put to sleep. There is a windows and linux version. They didn't mention mac but I bet it will compile and run on a mac too. :)
I hope this helps. I will probably use this myself in the future.