One way is with a direction vector.
Subtract one object’s position from the other and normalize that.
DirX=Ax-bx
DirY=ay-by
Dirz=az-bz
Length=sqrt(dirx^2+diry^2+dirz^2)
Dirx=dirx/length
DirY=diry/length
Dirz=dirz/length
I’d recommend reading some tutorials about vector math. It’s useful for 3d stuff even if you just learn the basics.
There are other ways to define angles in 3d: spherical coordinates, axis angle, 3x3 matrices, quaternions. They all have their uses.