Unless you get very lucky with housing living off $40k/year is pretty difficult in San Francisco. Even if you manage I would definitely not call it comfortable.
I don't find SF to be any more expensive than any other "big" city outside of housing cost, especially when you factor in not needing a car to get around.
But if I did, there's the premium tax credit, which caps premiums to some % of your annual income. For a single person, 322% above the federal poverty line is $40k with a 9.56% cap, so you'd pay no more than $318 in premiums a month and whatever you pay extra (say $182 for a $500 premium) becomes a tax credit.
echo "1.07^15" | bc -l
Of course, on $40k/year I suppose one would be taking subsidies or medicaid instead of paying full freight. But, then I guess it could be said you can make it in SF on $0/year...