Let's assume that the projectile must rise from height $y_0$ above the reference plane to height $y_\max$ and then descend to height $y_0 + y.$ That is, $y_\max > y_0$ and $y_\max > y_0 + y.$
You can set $y_\max$ however you want as long as it satisfies both of those inequalities.
This implies you'll always be firing at some upward angle, even at targets far below, and the projectile will always hit the targets at a downward angle, even if the target is far above you. But it means we can divide the trajectory into an upward portion that ends with zero vertical component of velocity and a downward portion that begins with zero vertical component of velocity.
We start by computing how long it takes to reach height $y_\max$, starting from height $y_0,$ if the vertical component of velocity at $y_\max$ must be zero. This is the same as the time to fall from height $y_\max$ to height $y_0$ starting from rest.
In time $t_1,$ starting from rest, supposing that $g$ is a positive number, a body will fall a distance $d = \frac12 gt_1^2.$
We need that distance to be $y_\max - y_0,$ so we need to ensure that
$$ \frac12 gt_1^2 = y_\max - y_0. $$
Solving for $t_1,$
$$ t_1 = \sqrt{\frac{2(y_\max - y_0)}{g}}. $$
The initial vertical component of velocity $v_{0y}$ that is needed in order to reach height $y_\max$ from height $y_0$ is the same as the final vertical velocity falling from $y_\max$ to $y_0$, which is $gt_1$ (the speed gained during the time it takes to fall that distance); that is,
$$ v_{0y} = gt_1 = \sqrt{2g(y_\max - y_0)}. $$
The time to fall from height $y_\max$ to height $y_0 + y$ is similarly
$$ t_2 = \sqrt{\frac{2(y_\max - y_0 - y)}{g}}. $$
(Just use $y_\max - (y_0 + y)$ instead of $y_\max - y_0$ in the formula we used for $t_1.$)
So we now know $t_1,$ which is the time to travel from the shooter to the top of the arc, and $t_2,$ which is the time to travel from the top of the arc to the target.
Therefore in order to hit a target which is at horizontal distance $x$ as well as vertical distance $y$ from the shooter,
the projectile must be able to travel $x$ distance horizontally in time
$t_1 + t_2,$ that is, the horizontal component of velocity must be
$$ v_{0x} = \frac{x}{t_1 + t_2}. $$
The initial speed is therefore
$$ v_0 = \sqrt{v_{0x}^2 + v_{0y}^2} $$
and (assuming $x$ is positive) the initial angle is
$$ \theta = \arctan\left(\frac{v_{0y}}{v_{0x}}\right). $$