What's the best material to patch gaps between moulding and the wall?
This is a simple job for caulk.  Just get a tube, run a bead, and smooth with your finger.  Allow to dry, and paint it the same color as the baseboard.  If the space is wide enough, first try to close the gap by nailing the moulding into the closest stud.  If the caulk shrinks too much, after it dries you can run another bead on top.

Note that spackle would crack when the baseboard moves.