My attempt:
A field can be constructed by taking the quotient by a maximal ideal. $\mathbb Z/2\mathbb Z[x]$ is a PID, so a maximal ideal can be made by taking an ideal generated by an irreducible.
$x^3+x+1$ is irreducible. (I checked by cases. Is there a better method?)
Then $\mathbb Z/2\mathbb Z[x]/(x^3+x+1)$ consists of elements of the form $\delta_1 x^2+\delta_2 x+\delta_3, \delta_i=0$ or $1$. This is because the polynomials of degree greater than 2 get simplified by the relation $x^3=x+1$. Thus we have $2^3$ elements in our field.
Is my solution correct? I feel like the first sentence in the last paragraph (starting with Then) is not that precise. Also, to generalize this question, in $\mathbb Z/p\mathbb Z[x]$, to find a field of size $p^n$, can I use the maximal ideal $(x^n+x+1)$?
Your solution for the case $p=2$ is correct.
Concerning a better method for checking that $x^3+x+1$, another one could be to check if any of the elements $\{0,1\}$ is a root: if a polynomial of degree 3 is reducible, then it will at least factor as a product of a polynomial of degree one and one of degree two.
Concerning the conclusion (the sentence after "then") it is correct as well. If you want to be a bit more formal, you may prove that the assignment $$\mathbb{Z}_2\times \mathbb{Z}_2\times \mathbb{Z}_2\to \mathbb{Z}_2[x]/(x^3+x+1)$$ given by $(a,b,c)\mapsto ax^2+bx+c$ is bijective. This will tell you that your field has $2^3$ elements (caveat: not that $\mathbb{Z}_2[x]/(x^3+x+1)$ is a field! That you know because you are quotienting a commutative unital ring by a maximal ideal. In fact, $\mathbb{Z}_2\times \mathbb{Z}_2\times \mathbb{Z}_2$ is not a field and the assignment above is not multiplicative, it is just $\mathbb{Z}_2$ linear).
Concerning the general question, I suspect you want to have that $x^n+x+1$ is irreducible to have a field with $p^n$ elements. If that's the case then yes, you can do that. However, in general, I don't think that's the correct polynomial you want to look at. Have a look at this answer.