f is analytic except possibly on $|z|=1$ and agrees with entire function $g$ when $|z|=1$, then $f$ is entire. A question from a past qualifying exam at my university reads
"Let $f$ be continuous on $\mathbb{C}$ and analytic except possibly on the unit circle
$\{|z| = 1\}$. Suppose that there is an entire function $g$ such that $f(z) = g(z)$
for $|z| = 1$. Prove that $f = g$ (and hence $f$ is entire)."
If one sets $h(z)=g(z)-f(z)$, then $h$ is identically zero on the unit circle, so using the maximum principle, one can conclude that $h$ is zero on the unit disk. Hence $f$ and $g$ agree on the closed unit disk. I do not know how to proceed from here. I have thought about using Morera's theorem, but to no avail.

You've taken care of the case $|z|<1.$ For $|z|>1,$ I'll use this:
Lemma: Let $A=\{1<|z|<2\}.$ Suppose $h$ is holomorphic on $A$ and continuous on $\overline A.$ If $h(z)=0$ for $|z|=1,$ then $h\equiv 0$ in $A.$
Proof: Note that the map $z\to 2/z$ is a bijection of $\overline A$ to $\overline A$ that is holomorphic on $A.$ Also note that this map interchanges the boundary circles.
Consider now the function $h(z)h(2/z).$ This function is holomorphic on $A,$ continuous on $\overline A,$ and equals $0$ on $\partial A.$ By the maximum modulus theorem, $h(z)h(2/z)=0$ everyhere in $A.$
Suppose $h(z_0)\ne 0$ for some $z_0\in A.$ Then $h(z)\ne 0$ in some $D(z_0,r).$ That implies $h(2/z)=0$ in $D(z_0,r),$ and hence in all of $A$ by the identity principle. But the range of $h(2/z)$ equals the range of $h(z),$ contradiction. So $h=0$ in all of $A,$ proving the lemma.
Back to your problem: Simply let $h=f-g,$ apply the lemma to get $f=g$ in $A,$ and then use the identity principle to see $f=g$ in all of $\{1<|z|<\infty\}.$
