You truly are a courageous Yid!!
I definitely relate to your position. I have struggled a lot with deflating feelings and self-doubt and low self-worth, mainly with regards to hatzlacha in learning, and unfortunately often my response was to distract myself with problematic behaviors. I really feel your pain! I don't know if I have a good eitzah, I really wish I did, but I do have some thoughts to share:
1) Lemaiseh, even though in the moment giving in is pleasurable and an escape, I think afterwards it doesn't feel very good. It always left me feeling worse than before - not only am I not matzliach in learning, I also can't control myself and abstain from a terrible aveirah?! So it might be of some help (if your experience is the same) to think about that when the urge comes, that it won't really help in the long term.
2) The beginning is admittedly very very difficult, but if you can manage to break the habit - the instinctive recourse to P&M whenever you're feeling down - it will become easier and you won't feel the urge to do it as much even when times are hard and you're not feeling great.
3) Just realizing that the urge is coming not from lust but rather from sad feelings can make it easier. Admittedly, you obviously do realize that, as you wrote so eloquently, but perhaps thinking about it and focusing on it b'shaas maiseh could be of some help. Another aspect of this is that often we can get overwhelmed by our emotions pulling us in different directions and lose clarity about what it is we really want. It helps sometimes to acknowledge all the different desires affecting us (e.g., I realize I'm not feeling very good about myself right now and that is making me want to escape with x, I acknowledge that I do want to do it and it will calm me down and give me that release I so badly need. At the same time, I know that it is not the right thing to do, and I know it will not lead to lasting fulfillment or happiness in the long term.), as this can let us regain clarity about the different options and their pros and cons, allowing us to make a calm decision. Not easy (and I hope it made sense), but it has worked for me.
4) When difficult emotions are the root of an urge, it can help to speak out those feelings (not necessarily the urge itself) with someone else. It restores our equilibrium and calms us down. This is also admittedly difficult, and I don't know if you have someone with whom you can speak about such feelings, but there are many wonderful Yidden here on the forum who are more than willing to listen and offer their help - consider reaching out to them! It's not easy, but I know for myself that connection to other people was something that changed my life and made my struggle so much easier.
Imo anochi b'tzarah and rooting for your success,
Yekusiel