Luckily I just happened to have one of my own to do (in my case repairing plaster around an old work box, but exactly the same process), so I'll give a walk-through of repairing the gap on the left:
What I usually do is fill the gap with wads of rolled up fiberglass joint tape:
Pack the wads of fiberglass into the gap (I'm using a screwdriver because the gap on mine is pretty narrow). For wider gaps, you can either fold them into 'U' shapes or make larger balls of tape. Doesn't really matter how you do it as, but fill up the gap.
When you're done, it should look something like this:
Make sure none of the fiber strands poke out beyond the plane of the wall (or you'll have to deal with it later during sanding and painting when it's more of a pain). Then, run a strip of fiberglass tape down the side of the box flush with the plane of the wall. You'll want to use a full width strip - mine is cut narrower because I'm working next to the trim:
Then, use a putty knife to pack mud into the gap. For really wide gaps, take your time so you don't push the fiberglass backing out:
Skim coat the tape smooth with the wall, and you should end up with something like this:
I've used the same method to fill in gaps around boxes as wide as an inch and haven't had any problems. The first "coat" will take a long time to dry, and the wider the gap, the longer it will take. It may also run a crack down the mud as it shrinks while it's drying, but that's fine - just pack mud into the crack on the next coat. After this point, it's basically like finishing any other mud joint.