The short answer is: both.
Abundant research shows that people with mood disorders are at high risk for substance use disorders. And it also shows that people with substance use disorders are at high risk for mood disorders. This has led to many chicken-and-egg arguments about which comes first or which is the true cause. Like the original chicken-and-egg argument, there is no single answer for every person or situation. Either one can cause or worsen the other.
Your practical question does have a single answer. Research has shown that combined treatment—addressing both mood disorder symptoms and substance use problems at the same time—is the most effective approach. In decades past, some psychiatrists believed that it was inappropriate to prescribe medications for a mood disorder, or even to diagnose a mood disorder, until someone had been clean and sober for months. We now know that such a restrictive approach is unnecessary and, possibly, even harmful. For example, people with depression who also abuse alcohol are more likely to decrease or stop drinking if they receive effective medication treatment for depression.
People who have had problems with substance abuse should probably avoid potentially addictive medications, like benzodiazepines. But those medications are not generally recommended treatments for depression or bipolar disorder.
The same recommendation about combined treatment holds for counseling or psychotherapy. Many of the counseling approaches proven effective for treatment of depression or bipolar disorder can also help people decrease or stop using alcohol or drugs. The “active ingredients” of those approaches include recognizing and interrupting negative thoughts, increasing involvement in positive activities, and identifying “triggers” or situations that can increase risk for substance use and/or mood episodes.