Is it possible to safely mimic the above setup with Arduino, and make up to city code?
Yes, it would be possible - as far as whether you could get it to pass code inspection, that is unknown - maybe?
The real question is, should the unthinkable happen, and your house burns down, and the fire department or inspector determines it was due to an electrical issue (whether due to your system or not) - will your insurance policy cover your house for the damages?
The answer will very likely be "no".
If you don't have insurance (?) - then the above concern is moot, and you can do what you want, and you'll have to live with any potential consequences (but that's life).
Personally, if I was tackling this project, I would try to use commercial-off-the-shelf (COTS) parts for the light and outlet controls (plus any other controls).
Ideally, these controls would be RF actuated, or perhaps actuated/controlled via a signal over the mains power lines (ie - something like X-10, just more reliable). If not either of those, then hard-wired would be OK (use in-wall or plenum rated cabling for the wiring, though - again, this is for any insurance coverage aspect) - but still, the control/actuation should happen at the light/plug - and those controllers should be COTS.
Then - try to obtain the spec for actuating those contollers, or reverse-engineer the signals. Basically, you want a line of demarcation between your system, and the actual devices controlling the electricity. You don't want to modify or otherwise change the controllers themselves, because doing so would bring into question any testing and certification (ie - UL standard or similar) that deems them "safe for use in a home environment" - again, this would be for insurance reasons.
If insurance or other similar reasons aren't an issue for you, then I would just go completely custom for everything - provided it was the cheaper option, and you have the skills to make it electrically safe and robust to use for 20 years or so.