Accurate calculations of electrostatic potentials and treatment of substrate polarizability are critical for predicting the permeation of ions inside water-filled nanopores. The {it ab initio} molecular dynamics method (AIMD), based on Density Functional Theory (DFT), accounts for the polarizability of materials, water, and solutes, and it should be the method of choice for predicting accurate electrostatic energies of ions. In practice, DFT coupled with the use of periodic boundary conditions in a charged system leads to large energy shifts. Results obtained using different DFT packages may vary because of the way pseudopotentials and long-range electrostatics are implemented. Using maximally localized Wannier functions, we apply robust corrections that yield relatively unambiguous ion energies in select molecular and aqueous systems and inside carbon nanotubes. Large binding energies are predicted for ions in metallic carbon nanotube arrays, while with consistent definitions Na$^+$ and Cl$^-$ energies are found to exhibit asymmetries comparable with those computed using non-polarizable water force fields.