Theory of local magnetic moments in transition metals