A free boundary problem arising in PDE optimization