We consider the integral:
$$
I = \int_{ - \infty }^{ + \infty } \frac{1}{\left( e^x + x + 1 \right)^2 + \pi^2} \, dx
$$
We express the denominator as a product of conjugates:
\begin{align}
I &= \int_{ - \infty }^{ + \infty } \frac{1}{\left( e^x + x + 1 + i\pi \right)\left( e^x + x + 1 - i\pi \right)} \, dx \\
&= \frac{1}{2i\pi} \int_{ - \infty }^{ + \infty } \left( \frac{1}{e^x + x + 1 - i\pi} - \frac{1}{e^x + x + 1 + i\pi} \right) dx
\end{align}
We make the substitution $x = z \pm i\pi$ in the integrals:
\begin{align}
I &= \frac{1}{2i\pi} \left( \int_{ - \infty }^{ + \infty } \frac{1}{-e^{x - i\pi} + (x - i\pi) + 1} \, dx - \int_{ - \infty }^{ + \infty } \frac{1}{-e^{x + i\pi} + (x + i\pi) + 1} \, dx \right) \\
&= \frac{1}{2i\pi} \left( \int_{ -\infty - i\pi }^{ +\infty - i\pi } \frac{1}{ -e^z + z + 1 } \, dz - \int_{ -\infty + i\pi }^{ +\infty + i\pi } \frac{1}{ -e^z + z + 1 } \, dz \right) \\
&= \frac{1}{2i\pi} \left( \int_{ -\infty - i\pi }^{ +\infty - i\pi } \frac{1}{ -e^z + z + 1 } \, dz + \int_{ +\infty + i\pi }^{ -\infty + i\pi } \frac{1}{ -e^z + z + 1 } \, dz \right)
\end{align}
Let $f(z) = \frac{1}{ -e^z + z + 1 }$, and consider the rectangle $\gamma$ with vertices at $A(-M, -\pi)$, $B(M, -\pi)$, $C(M, \pi)$, and $D(-M, \pi)$, where $M > 0$.
Since $f(z)$ is analytic inside $\gamma$ except at poles, and $f(z) \ne 0$ on $\gamma$, and $\lim_{M \to \pm \infty} f(z) = 0$, we apply the residue theorem:
$$
I = \frac{1}{2i\pi} \cdot \lim_{M \to \infty} \oint_\gamma f(z) \, dz
$$
By the residue theorem:
$$
\oint_\gamma f(z) \, dz = 2i\pi \sum_k \text{Res}(f(z), z_k)
$$
We solve the pole condition:
$$
-e^z + z + 1 = 0 \Rightarrow e^{x+iy} = x + iy + 1
$$
Equating real and imaginary parts:
$$
e^x (\cos y + i \sin y) = x + 1 + iy \Rightarrow
\begin{cases}
e^x \cos y = x + 1 \\
e^x \sin y = y
\end{cases}
\quad \text{(System } \Sigma \text{)}
$$
An obvious solution is $z = 0$. Also, $y \ne \pm \pi, \pm \frac{\pi}{2}$ since these don't satisfy system $\Sigma$.
Solving $\Sigma$:
$$
\begin{cases}
e^x = \dfrac{y}{\sin y} \\
\dfrac{y}{\sin y} \cos y - \log\left( \dfrac{y}{\sin y} \right) - 1 = 0
\end{cases}
$$
So it's enough to analyze the function:
$$
g(y) = \frac{y}{\sin y} \cos y - \log\left( \frac{y}{\sin y} \right) - 1
$$
We restrict to $D^* = \left(-\frac{\pi}{2}, \frac{\pi}{2} \right) \setminus \{0\}$ since on $D - D^*$ it's clear $g(y) < 0$.
Compute derivative:
$$
g'(y) = -\frac{1}{y} \left( \frac{(\sin y - y \cos y)^2}{\sin^2 y} + y^2 \right)
$$
So:
\begin{cases}
g'(y) < 0 &\text{for } y \in (0, \frac{\pi}{2}) \\
g'(y) > 0 &\text{for } y \in (-\frac{\pi}{2}, 0)
\end{cases}
And since $\lim_{y \to 0} g(y) = 0$, we conclude $g(y) < 0$ for all $y \in D^*$.
Hence, $f(z)$ has only a real pole at $z = 0$ in the strip.
We solve:
$$
e^x - x - 1 = 0 \Rightarrow \text{only solution is } x = 0
$$
And since
$$
e^x - x - 1 = \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \cdots
$$
$x=0$ is a double root.
Therefore:
$$
\oint_\gamma f(z) \, dz = 2i\pi \cdot \text{Res}(f(z), 0)
= 2i\pi \cdot \lim_{z \to 0} \frac{d}{dz} \left( \frac{z^2}{ -e^z + z + 1 } \right) = \frac{4i\pi}{3}
$$
Finally:
$$
I = \frac{1}{2i\pi} \cdot \oint_\gamma f(z) \, dz = \frac{1}{2i\pi} \cdot \frac{4i\pi}{3} = \frac{2}{3}
$$