Maybe just "keep" the kid as something like a Little Sister?
Sort of like Big Brothers / Big Sisters, you familiar?
I do not mean like try to keep ownership, but if there is not a Mom-Ex that really cares for her, you can still do things together once a week, or a couple times a month?
That part is salvaging the good. A good thing.
-----------
And now the bad . . .
As far as him, maybe just consider it a "write off?" Like in business, or farming. We do not like to see a project, or crop, or person, or relationship "fail," but when they do, they can be studied a bit for understanding and to not repeat -- but we do not stay in the middle of the failure.
So weeds and weevils got this relationship crop. Does not mean there is a not a better one down the road. You still have you, you have plenty of go and good -- just do not waste that resource (you) on being stuck in someone else's bad.