A total-energy theory for a solid is presented. It is based on density-functional theory and consists of a succession of approximations. At the most accurate level, the theory consists of a systematic derivation of an ansatz for the electron density which is best suited for the Harris functional. At the most approximate level, the theory is equivalent to the usual effective-medium theory. At all levels of approximation, every term in the total-energy expression is calculated ab initio, that is, without any fitting to experiment or to other calculations. Every step in the approximation procedure can thus be tested independently. The theory is applied to calculations of the surface energies and vacancy formation energy of Al. At the most accurate level, the theory gives results that are in almost complete agreement with self-consistent calculations. At the more approximate, but also computationally much less demanding, level, the theory gives results that are still in excellent agreement with the self-consistent results.