Suppose $P\in\mathbb{Q}[x]$ is a polynomial of least degree such that
\begin{align*}
(x+1)^3&{\,\mid\,}(P(x)-1)\\[4pt]
(x-1)^3&{\,\mid\,}(P(x)+1)\\[4pt]
\end{align*}
Equivalently, $P\in\mathbb{Q}[x]$ is a polynomial of least degree such that
\begin{align*}
P(x)&=A(x)(x+1)^3+1\\[4pt]
P(x)&=B(x)(x-1)^3-1\\[4pt]
\end{align*}
for some polynomials $A,B\in\mathbb{Q}[x]$.
Necessarily, $A,B$ have the same degree.
Let $u=(x+1)^3$ and let $v=(x-1)^3$.
If $A,B\in\mathbb{Q}[x]$ are polynomials of least degree satisfying $Au-Bv=-2$, then we have $Au+1=Bv-1$, hence $P=Au+1$ is a polynomial in $\mathbb{Q}[x]$ of least degree satisfying the specified requirements.
The equation $Au-Bv=-2$ is equivalent to $-\bigl({\large{\frac{A}{2}}}\bigr)u+\bigl({\large{\frac{B}{2}}}\bigr)v=1$, hence we have $A=-2a$ and $B=2b$, where $a,b\in\mathbb{Q}[x]$ are polynomials of least degree satisfying $au+bv=1$.
Since $u,v$ are relatively prime in $\mathbb{Q}[x]$, there are unique polynomials $a,b\in\mathbb{Q}[x]$ with
- $\deg(a) < \deg(v) = 3$$\\[4pt]$
- $\deg(b) < \deg(u) = 3$
such that $au+bv=1$, so these are the polynomials $a,b$ we want.
The polynomials $a,b$ can be found via the Extended Euclidean Algorithm.
Here are the steps . . .
\begin{align*}
(x+1)^3=(1)(x-1)^3+(6x^2+2)&\implies u-v=6x^2+2\\[4pt]
6(x-1)^3=(x-3)(6x^2+2)+16x&\implies (-x+3)u+(x+3)v=16x\\[4pt]
8(6x^2+2)=(3x)(16x)+16&\implies (3x^2-9x+8)u+(-3x^2-9x-8)v=16\\[4pt]
\end{align*}
from which we get
\begin{align*}
a&={\small{\frac{1}{16}}}(3x^2-9x+8)\\[4pt]
b&={\small{\frac{1}{16}}}(-3x^2-9x-8)\\[4pt]
\end{align*}
which yields
\begin{align*}
A&=-2a=-{\small{\frac{1}{8}}}(3x^2-9x+8)\\[4pt]
B&=2b={\small{\frac{1}{8}}}(-3x^2-9x-8)\\[4pt]
\end{align*}
hence
\begin{align*}
P&=Au+1\\[4pt]
&=\left(-{\small{\frac{1}{8}}}(3x^2-9x+8)\right)(x+1)^3+1\\[4pt]
&=-{\small{\frac{1}{8}}}(3x^5-10x^3+15x)\\[4pt]
\end{align*}