SELF-CONSISTENT THEORY OF ANDERSON LOCALIZATION: GENERAL FORMALISM AND APPLICATIONS