To factor $ x^2y+10y+4x^2+40 $ we can use factoring by grouping.
Group $ \color{blue}{ x^2y }$ with $ \color{blue}{ 10y }$ and $ \color{red}{ 4x^2 }$ with $ \color{red}{ 40 }$ then factor each group.
$$ \begin{aligned} x^2y+10y+4x^2+40 &= ( \color{blue}{ x^2y+10y } ) + ( \color{red}{ 4x^2+40 }) = \\ &= \color{blue}{ y( x^2+10 )} + \color{red}{ 4( x^2+10 ) } = \\ &= (y+4)(x^2+10) \end{aligned} $$