We consider shape optimization problems for general integral functionals of the calculus of variations, defined on a domain $Omega$ that varies over all subdomains of a given bounded domain $D$ of ${bf R}^d$. We show in a rather elementary way the existence of a solution that is in general a quasi open set. Under very mild conditions we show that the optimal domain is actually open and with finite perimeter. Some counterexamples show that in general this does not occur.