A complete solution to the inverse problem of Kohn-Sham (KS) density functional theory is proposed. Our method consists of two steps. First, the effective KS potential is determined from the ground state density of a given system. Then, the knowledge of the potentials along a path in the space of densities is exploited in a line integration formula to determine numerically the KS energy of that system. A possible choice for the density path is proposed. A benchmark in the case of a simplified yet realistic nuclear system is shown to be successful, so that the method seems promising for future applications.