\(x^2+2xy+y^2+6\left(x+y\right)+8=-y^2\)
\(\Leftrightarrow\left(x+y\right)^2+6\left(x+y\right)+8\le0\)
\(\Leftrightarrow\left(x+y+2\right)\left(x+y+4\right)\le0\)
\(\Rightarrow-4\le x+y\le-2\)
\(\Rightarrow2016\le B\le2018\)
\(B_{min}=2016\) khi \(\left(x;y\right)=\left(-4;0\right)\)
\(B_{max}=2018\) khi \(\left(x;y\right)=\left(-2;0\right)\)