Gaussian primes when $p \equiv 1\pmod {4}$ and $x^2 +1$ factors In watching a video from Prof. Gross's algebra course, there were some remarks for which I would appreciate explanations.
They were in a discussion of Gaussian primes, and in the case where $p \equiv 1\pmod {4}$, and $(x^2 +1)$ factors into $(x - a)(x + a)$ where $a^2\equiv - 1\pmod {p}$.
The lecture went on to say that these two factors are related to two roots whose related ideals are $(p, i - a)$ and $(p, i + a)$.
He then went on to point out that these are not principal. 
But here (at last) is my first question: he then said that these are both prime in $Z[i]$. How, please, can a non-principal ideal be considered prime? (I probably should know this, did try to look it up.)
Then he went on to show that there are only two elements of order $2$, $+1$ and $-1 \pmod {p}$ by the argument that $p\mid(a^2 - 1)$, and since $p$ is prime, $p\mid(a -1)$ or $p\mid(a + 1)$; thus $a = 1$ or $a = -1$.
My second question is where does $a^2 - 1$ come from, since, we are assuming $a^2 \equiv - 1\pmod {p}$.
Lastly, I was wondering how this leads to Fermat's Theorem where $p = a^2 + b^2$. I can see that since there are two roots above which are complex conjugates and there is the constraint on $p$, $p \equiv 1\pmod {4}$. But I would appreciate help pulling it together.
Thanks. These lectures were produced eight years ago, so although I would prefer it, there is no mechanism for me to go up after class, etc.
 A: If $R$ is a ring, an ideal $P$ is a prime ideal if and only if:


*

*$P\neq R$; and

*If $A$ and $B$ are ideals of $R$, and $AB\subseteq P$, then $A\subseteq P$ or $B\subseteq P$.


In commutative rings, this definition is equivalent to:

Let $R$ be a commutative ring. An ideal $P$ or $R$ is a prime ideal if and only if
  
  
*
  
*$P\neq R$; and
  
*If $a,b\in R$ are such that $ab\in P$, then either $a\in P$ or $b\in P$.
  

The definition does not require the ideal $P$ to be principal. 
To your second question: you are confusing the $a$ from the first part of the problem (which was a solution to $x^2\equiv -1\pmod{p}$), with a new variable $a$. Perhaps this will clarify it: if $r$ is an element that is of order $2$ modulo $p$, then $r^2\equiv 1\pmod{p}$, which means that $r^2-1\equiv 0\pmod{p}$, which means that $p|r^2-1 = (r-1)(r+1)$. He's just using $a$ to denote the putative element of order $2$. 
So that means that if $r$ is of exponent 2 (that is, $r^2\equiv 1\pmod{p}$), then either $p|r-1$ or $p|r+1$. If $p|r-1$, then $r\equiv 1\pmod{p}$; if $p|r+1$, then $r\equiv -1\pmod{p}$. Thus, the only two elements of exponent $2$ modulo $p$ are $1$ and $-1$, as stated.
As far as the connection to the so-called "Fermat's Christmas Theorem", or "Fermat's Theorem on the Sums of Two Squares", which says that an odd prime $p$ can be written as a sum of two squares if and only if $p\equiv 1\pmod{4}$, we have the following:
If $p= a^2+b^2$, then since $a^2,b^2\equiv 0,1\pmod{4}$ and $p$ is an odd prime, we must have $p\equiv 1\pmod{4}$.
Conversely, if $p\equiv 1\pmod{4}$, then in $\mathbb{Z}[i]$ we have that $p$ is not prime; therefore, $p$ can be written as $(a+bi)(a-bi)$ for some Gaussian integers $a+bi, a-bi$, and therefore $a^2+b^2=p$.
