Complete solution to the inverse Kohn-Sham problem: From the density to the energy