CBT is part of an integrated approach to these moods, and helps one learn to catch these thoughts as they happen, challenge them, and replace them with more accurate, and more positive assessments.
Negative thoughts breed negative moods
In using CBT we focus in on how thoughts are actually helping to trigger upwellings of depression and anxiety. Your mood is very responsive to thoughts; if you are constantly thinking negative thoughts, then it's impossible that your mood will not reflect it.
CBT has been heavily researched, and has been shown to be very effective in alleviating the worst of depression and anxiety. It can be surprising to see how impactful thoughts are, but it's absolutely true. When you learn to consciously shift your thinking, you both stop triggering the depression/anxiety, but you also start feeling in control of your inner life.
CBT is a way of taking apart old habits of thought, and putting in their place healthier patterns of thought that, because of the way the brain is wired, inevitably lead to more buoyant moods that sustain over time. This is the absolutely essential skills-building part of therapy.