How many moles of solid Mg(OH)2 should you add to 200mL of 0.15M lactic acid solution to produce pH 4.0 buffer?

Look up the pKa for lactic acid.

You have 200 x 0.15M HL(lactic acid) = 30 millimols HL.

Set up an ICE chart. You have 30 mmols HL and zero OH^- and zero L^-. You want to add NaOH to it to form the L^- and take away from the HL while doing that.
...........HL + OH^- ==> L^- + H2O
I.........30.....0.......0......0
add..............x..................
C.........-x....-x.......x........
E........30-x....0.......x

Now substitute the E line into the HH equation.
4.0 = pKa + log (x)/(30-x)
Solve for x = millimols OH^- needed to do the job. I would convert that to mols, take half of it (since Mg(OH)2 provides twice as much OH per 1 mol Mg(OH)2), then mols x molar mass = grams Mg(OH)2.
I never work one of these without checking it and I recommend you do the same. Start with ? grams Mg(OH)2 [I think the g is approximately 0.5 g], add that to the 0.030 moles HL, check to see how much HL is left and how much L^- is formed (you can do that with regular stoichiometry), stick those back into the HH equation and see if you end up with a pH of 4.0. You did something wrong if you don't get that; I did when I checked my answer.
Post your work if you get stuck.