A self-consistent treatment of Anderson localization