You haven't provided enough information to solve your problem.
If the other aircraft was stationary (as an extreme example), you would transit his altitude at the greatest separation by climbing at the maximum gradient.
At any other speed you need to calculate both cases, but I think the optimum speed will likely be between Vx and Vy.
If you plot ROC Vs Airspeed, Vx is obtained by finding the tangent point of a line drawn from the origin that is tangential to the curve.
I think the solution to your problem is obtained by plotting that tangent from (-
Vb) where
Vb is the velocity of the other aircraft.
Similar to doing the best-range-speed problem with head or tailwinds