How can I seal around a light fixture/light switch outlet?
If the gap is small enough, you can just use some general purpose caulk.  For bigger gaps, patch it with some mud or spackle, then caulk to finish.  Since it's going to be hidden behind a light fixture, it doesn't even have to be that pretty!

(They do make a fire-retardant foam, but I look at the  warning labels and get nervous when they say "extremely flammable while curing.“)