Construction of optimal background fields using semidefinite programming