Your approach is correct, and it’s probably the simplest one. To finish it off, let $\mathscr{J}$ be your collection of maximal open intervals. Every open interval contains a rational number, so for each $J\in\mathscr{J}$ let $q_J\in J$ be rational. Since distinct members of $\mathscr{J}$ are disjoint, the mapping $\mathscr{J}\to\mathbb{Q}:J\mapsto q_J$ is an injection (one-to-one), and therefore $|\mathscr{J}|\le |\mathbb{Q}|$. Since $\mathbb{Q}$ is countable, this implies that $\mathscr{J}$ is countable.
For completeness I’ll include a rigorous way to get the intervals in the first place. Define an equivalence relation $\sim$ on $[a,b]$ by setting $x\sim y$ iff either $x\le y$ and $f(z)\ne 0$ for all $z\in[x,y]$, or $y\le x$ and $f(z)\ne 0$ for all $z\in[y,x]$. It’s easy to check that this is an equivalence relation whose equivalence classes are intervals, and the continuity of $f$ implies that these intervals are open.