General Problem
The general problem is below, however, I am interested in the case where $f(x)=\cos(x)$.
Find a polynomial $P(x)$ such that the function $F(x)=\frac{d}{dx}\left(P(x)f(x)\right)$ has unique roots at the points $0,\pm a,\pm b$. The function $F(x)$ is not defined when $P(x)$ or $f(x)$ themselves are equal to 0.
Case of $f(x)=e^{-x^2}$
This case is very simple. Notice that $F(x)$ will never be undefined in this case as our function $f(x)=e^{-x^2}$ is never equal to $0$. It can be solved by first calculating the derivative using the chain rule, factoring out $e^{-x^2}$, leaving us with a function $H(x)$:
$$H(x)=P'(x)-2xP(x)$$
Given that we need $H(x)$ to meet the condition of the roots occurring at $0,a,-a,b,-b$ we could define it as the following expression:
$$H(x)=x(x-a)(x+a)(x-b)(x+b)=x(x^2-a^2)(x^2-b^2)=x^5-(a^2+b^2)x^3+a^2b^2x$$
Since $H(x)$ is quintic, we can deduce that $P(x)$ must be quartic, thus defining it in general terms as: $$P(x)=\alpha x^4 +\beta x^3+\gamma x^2 +\delta x +\epsilon $$ $$P'(x)=4\alpha x^3+3\beta x^2+2\gamma x+\delta$$ Meaning, $P'(x)-2xP(x)=-2\alpha x^5-2\beta x^4+(4\alpha-2\gamma)x^3+(3\beta-2\delta)x^2+(2\gamma-2\epsilon)x+\delta$. At this point we have two equations for $H(x)$ which we can simply compare the coefficients to determine $\alpha, \beta, \gamma, \delta,\epsilon$, and thus: $$P(x)=-\frac{1}{2} x^4 +\left(\frac{a^2+b^2}{2}-1\right) x^2+\frac{a^2+b^2-a^2b^2-2}{2}$$
Case of $f(x)=\cos(x)$
If we start with the same method as above, we first take the derivative using the chain rule giving us: $$P'(x)\cos(x)-P(x)\sin(x)=0$$ Here, however, there is no apparent way to factor out something from this expression, so I tried using the complex definitions of $\cos(x)$ and $\sin(x)$ to see if it would work, giving us the equation: $$P'(x)\left(\frac{e^{ix}+e^{-ix}}{2}\right)-P(x)\left(\frac{e^{ix}-e^{-ix}}{2i}\right)=0$$ Simplifying, we get: $$\frac{1}{2}P'(x)\left(e^{ix}+e^{-ix}\right)+\frac{i}{2}P(x)\left(e^{ix}-e^{-ix}\right)=0$$ Now there still seems to be an issue, as the exponential terms are conjugates of themselves and not easily factored. One can try factoring out $(e^{ix}+e^{-ix})$, to see if there is a possible simplification. Note that we don't need to worry about the zeroes of $(e^{ix}+e^{-ix})$ as they are the same as $\cos(x)$ for which $F(x)$ is undefined. $$\left(e^{ix}+e^{-ix}\right)\left(\frac{1}{2}P'(x)+\frac{i}{2}P(x)\frac{\left(e^{ix}-e^{-ix}\right)}{\left(e^{ix}+e^{-ix}\right)}\right)=0$$ Indeed, one can reach the following simplification by multiplying by conjugates and squaring: $$\frac{\left(e^{ix}-e^{-ix}\right)}{\left(e^{ix}+e^{-ix}\right)}=\left(e^{ix}\right)^2-1$$ We still, however, would need to find what $\left(e^{ix}\right)^2$ is in terms of $P(x)$ This can be done by expanding our previous equation, grouping the corresponding $e^{ix}$ and $e^{-ix}$ terms: $$\frac{1}{2}P'(x)\left(e^{ix}+e^{-ix}\right)+\frac{i}{2}P(x)\left(e^{ix}-e^{-ix}\right)=\frac{1}{2}P'(x)e^{ix}+\frac{1}{2}P'(x)e^{-ix}+\frac{i}{2}P(x)e^{ix}-\frac{i}{2}P(x)e^{-ix}=e^{ix}\left(\frac{1}{2}P'(x)+\frac{i}{2}P(x)\right)+e^{-ix}\left(\frac{1}{2}P'(x)-\frac{i}{2}P(x)\right)=0$$ Now simply multiply both sides of the equation by $e^{ix}$: $$\left(e^{ix}\right)^2\left(\frac{1}{2}P'(x)+\frac{i}{2}P(x)\right)+\left(\frac{1}{2}P'(x)-\frac{i}{2}P(x)\right)=0$$ Isolating for $\left(e^{ix}\right)^2$ we get the following expression: $$\left(e^{ix}\right)^2=\frac{\frac{i}{2}P(x)-\frac{1}{2}P'(x)}{\frac{i}{2}P(x)+\frac{1}{2}P'(x)}$$ Therefore: $$\left(e^{ix}\right)^2-1=\frac{\frac{i}{2}P(x)-\frac{1}{2}P'(x)}{\frac{i}{2}P(x)+\frac{1}{2}P'(x)}-\frac{\frac{i}{2}P(x)+\frac{1}{2}P'(x)}{\frac{i}{2}P(x)+\frac{1}{2}P'(x)}=\frac{-P'(x)}{\frac{i}{2}P(x)+\frac{1}{2}P'(x)}$$ Now we can finally substitute this back into our original equation, giving us a new $H(x)$ expression of: $$H(x)=\frac{1}{2}P'(x)-\frac{P(x)P'(x)}{P(x)-iP'(x)}$$
In the previous example, the next step would be to deduce what the degree of $P(x)$ is (given that we know $H(x)$ must be quintic), and from there one simply inputs the general expression for a polynomial of that degree into our $H(x)$ function, comparing the coefficients to that of a general quintic polynomial. However, I'm not quite sure how to deduce the degree of $P(x)$ from the above function, or if there even is such a $P(x)$ where our $H(x)$ reduces to a polynomial, which should be necessary.
Is it possible to deduce the degree of $P(x)$, or should I try some other method?
I'm making this an answer because I have something more to add and I don't want to spam the comments.
So as I said, we can define the polynomial: $$f(x)=x(x−a)(x+a)(x−b)(x+b)$$ and then take $P(x)$ to be: $$P(x)=(f(x))^2$$ Then we have that $P'(x)=2f'(x)f(x)$, and hence, we get:
$$\frac{d}{dx}(P(x)\cos(x))=P′(x)\cos(x)−P(x)\sin(x)=f(x)(2f′(x)cos(x)−f(x)sin(x))$$
which has $0,a,-a,b,-b$ as roots, since $f(x)$ does. (Note these are not necessarily the only roots of the derivative).
It turns out that we can actually lower the degree of $P(x)$ and still have these $4$ roots.
To do that, you can instead define: $$g(x)=(x−a)(x+a)(x−b)(x+b)$$ which is similar to $f(x)$ but without the factor $x$.
Calculating $g'(x)$ gives us: $$g'(x)=2x(2x^2-a^2-b^2)$$ In particular $g'(x)$ has a root at $x=0$.
Now, define $P(x)=(g(x))^2$, and doing the exact same calculations as before, we arrive at: $$\frac{d}{dx}(P(x)\cos(x))=g(x)(2g′(x)cos(x)−g(x)sin(x))$$
Again, this equation has the four roots of $g(x)$, namely $a,-a,b$ and $-b$.
But notice that for $x=0$, we have: $g'(0)=0$ and also: $\sin(0)=0.$
Hence: $$\frac{d}{dx}\Bigr|_{x=0}(P(x)\cos(x))=0$$
Thus, we achieved again the requirment that $\frac{d}{dx}(P(x)\cos(x))$ has roots at $0,a,-a,b,-b$, but this time with a polynomial of lower degree than before.