You can't do all of that at the same time.
You want to add lean muscle gains? Focus on that.
You want to continue to lose body fat? Focus there.
You want to perform well during your tri? Focus on endurance.
You're fighting a frustrating, losing battle trying to do all three because they involve 3 completely different training and nutrition strategies.
Depending on where your endurance is at you could split up the focus into three phases - muscle build, cutting, then endurance.
But if you need a lot of training for endurance then I would forget the cutting phase. Focus on that after the tri. You'll likely lose weight during the endurance training anyway, just not as much. Plus your performance will be better.
So focus on a legitimate muscle gains plan for at least 3 months with minimal cardio, then focus on endurance for the five months until your race (but still incorporate weights as s means of cross-training and to keep up your strength.)
Work on leaning out after the race.
TL;DR - Focus on what you what to succeed in because you can't do it all.