We study the existence and regularity of optimal domains for functionals depending on the spectrum of the Dirichlet Laplacian or of more general Schrödinger operators. The domains are subject to perimeter and volume constraints; we also take into account the possible presence of geometric obstacles. We investigate the properties of the optimal sets and of the optimal state functions. In par…