So if I have a complex number x+iy and we want to find the angle ϴ it makes with the x axis we can get it by the arctan (y/x) formula and ϴ would be in any one of the four quadrants based on the x and y values
However, if we use the arctan formula for definite integration we have to strictly stay between π/2 and -π/2. Can someone tell me why do we have such an ambiguity ?
Tha function $\tan x$ is not bijective on the whole interval of definition and thus it is not invertible.
To make it invertible, usually, we choose the interval $(-\pi/2, \pi/2)$ to define $\arctan x$, exactly as we do to define the inverse of $x^2$ that is $\sqrt x$.
Refer also to: Inverse trigonometric functions.
Note that, in your specific case, once you have evaluated
$$\theta_0=\arctan (y/x)$$
you need to adjust the answer by adding $\pi\pm 2k\pi$ in order to obtain the correct value for $\theta$. Notably when $x<0$ we need to add (or subtract) $\pi$, etc.