  We develop a technique for generating a set of optimized local basis
functions to solve models in the Kohn-Sham density functional theory for both
insulating and metallic systems. The optimized local basis functions are
obtained by solving a minimization problem in an admissible set determined by a
large number of primitive basis functions. Using the optimized local basis set,
the electron energy and the atomic force can be calculated accurately with a
small number of basis functions. The Pulay force is systematically controlled
and is not required to be calculated, which makes the optimized local basis set
an ideal tool for ab initio molecular dynamics and structure optimization. We
also propose a preconditioned Newton-GMRES method to obtain the optimized local
basis functions in practice. The optimized local basis set is able to achieve
high accuracy with a small number of basis functions per atom when applied to a
one dimensional model problem.
