How to find an integer matrix $P$ such that $PAP^{-1}=B$ for given two similar, integer matrices $A$ and $B$?

Note that $\chi_A(x)=\chi_B(x)=p(x)=x^3-40x^2+39x-1$ is irreducible and has $3$ distinct roots $(\lambda_i)$. Here $PA=BP$ with $\det(P)=1$; then $P$ sends any eigenvector of $B$ associated to $\lambda_i$ to an eigenvector of $A$ associated to the same $\lambda_i$; moreover, the eigenvectors are defined up to a multiplicative constant. The set $\{R;RA=BR\}$ is a vector-space of dimension $3$. Then an equality of the form $Ru=v$, where $u,v$ are given vectors, define in general a unique $R$.

An eigenvector of $A$ (resp. of $B$) associated to $\lambda_i$ is $U_i=[1+37\lambda_i,3\lambda_i,-2\lambda_i+\lambda_i^2]^T$ (resp. $W_i=[1+297\lambda_i,155\lambda_i,-12\lambda_i+\lambda_i^2]^T$) and $P(U_i)=a_iW_i$ where $a_i\in\mathbb{C}$. It is easy to see that $U=\sum_iU_i=[1483,120,1442]^T$ and $P(U)=\sum_ia_iW_i$ is an integer vector.

Thus (*) $\sum_ia_i,\sum_ia_i\lambda_i,\sum_ia_i\lambda_i^2$ are rational numbers and the $(a_i)$ are in $F$, the decomposition-field of $p$. On the other hand, $\dfrac{\det(U_1,U_2,U_3)}{\det(W_1,W_2,W_3)}=3/155$ implies that $a_1a_2a_3=3/155$.

Consequently, the $(a_i)$ are the roots of a polynomial $q(y)$ that is the image of $p$ by a transformation $y=u+vx+wx^2$ where $u,v,w$ are rational numbers. Note that $q$ must be in the form $q(y)=y^3+\cdots-3/155$. We seek solutions $(u,v,w)$ in the form $n/155$ where $n\in\mathbb{Z}$ and we obtain $3$ candidates: $(-13/155,28/155,-1/155),(-1/155,26/155,-12/155),(12/155,-2/155,-11/155)$ (maybe there are other solutions). It remains to see that the associated solutions $P$ are (or are not) integer-matrices.

Case 1. We obtain $P(U)=[-33012,-17227,-3004]^T$ and $P$ is the matrix obtained by Axel Kemper (with the little radius). $P$ is an integer matrix and is convenient.

Case 2. We obtain $P(U)=[-1288409,-672344,-117124]^T$, $P=\begin{pmatrix}-23&2&-870\\-12&1&-454\\-2&-2&-79\end{pmatrix}$ and $P$ is convenient.

Case 3. We obtain $P(U)=[-1255397,-655117,-11412]^T$; yet, $P$ is not an integer matrix and is not convenient

EDIT. Answer to @user7540.

Since $galois(p)=S_3$, there are no algebraic relations with coefficients in $\mathbb{Q}$ linking the $(a_i)$ and there is a cycle $\sigma\in Galois(p)$ s.t. $\sigma(\lambda_i)=\lambda_{i+1}$. According to (*) above, $a_i\in F$, the decomposition-field of $p$ and (reverse the Vandermonde matrix) $a_1=u+v\lambda_1+w\lambda_i^2,a_2=\sigma(a_1),a_3=\sigma(a_2)$, where $u,v,w$ are rational numbers. Finally, the $(a_i)$ are the roots of a polynomial that is the image of $p$ by the transform $x\rightarrow u+vx+wx^2$.