You can get the longitude by taking $\arctan \frac yx$ and correcting for the quadrant. If you have Atan2 available it will take care of the quadrant. Then you can find the $\cos$ and $\sin$ of that and divide them out. Now you just need an $\arccos$ to get there.