I need to develop $\cos\theta$ so that the expression doesn't contain $x$ (or any expressions containing $x$). The point $P$ is at $(x,y)$.
Given are:
- $|AB| = D = \text{constant}$
- $|AP|+|BP|= L = \text{constant}$
Despite several attempts I just don't seem to be able to get rid of $x$. Is it even possible or am I overlooking something?

The data you have provided do not determine $x$ or $\theta$. For fixed $L$ the point $P$ can be anywhere on an ellipse with foci $A$ and $B$.
Either one of $x$ and $\theta$ determines the other, and $P$. If you specify $P$ some other way you can calculate $\theta$ from that data without finding $x$ first.
So the answer to the question as you've asked it is that you can't get rid of $x$.