Recall that the differential of f(x,y) is
df = (df/dx)dx + (df/dy)dy
Now look at the ODE you were given. It matches this form. This means that there could be a function f whose differential is the given ODE and whose value df = 0.
If this is true, then P = df/dx, Q = df/dy.
We know that the mixed partial derivatives of a function equal eachother, so an easy way to check if f exists is to take the derivative of P wrt y and the derivative of Q wrt x and see if they equal eachother.
In your case, they both equal -sin(y)cos(x) and so we know f exists. We call this ODE exact.
Now the task is to find f. You use the clues available to you.
Take the integral of P wrt x:
f(x,y) = -cos(x)cos(y) + C
We know C cannot be a function of x, since it disappears upon differentiation wrt x, so this becomes
f(x,y) = -cos(x)cos(y) + h(y)
Now take df/dy and see how it compares with Q.
df/dy = -cos(x)sin(y) + h'(y) = cos(x)sin(y)
h'(y) = 2cos(x)sin(y)
Integrate
h(y) = -2cos(x)cos(y) + C
Now we know what f is.
f(x,y) = -cos(x)cos(y) - 2cos(x)cos(y) + C
= -3cos(x)cos(y) + C
Since the differential of f is 0, we can say that f = D, some constant, since the differential of a constant is always 0.
D = -3cos(x)cos(y) + C
Combining constants and solving for y gives
y = arccos(C/cos(x))
Note: The constant of integration in h is usually ignored, since it always combines later.