Self-Consistent Theory of Anderson Localization: General Formalism and Application