Just to agree on notation: A space is zero-dimensional if it is $T_1$ and has a basis consisting of clopen sets, and totally disconnected if the quasicomponents of all points (intersections of all clopen neighborhoods) are singletons. A space is hereditarily disconnected if no subspace is connected, i.e., if the components of all points
are singletons. (Edit: There seems to be disagreement about the names of these properties.
Often what I call hereditarily disconnected is called totally disconnected and what I call totally disconnected is then called totally separated.)
Note that zero-dimensionality implies Hausdorffness.
Zero-dimensional implies totally disconnected since every point can be separated from every other point by a clopen set.
Totally disconnected implies hereditarily disconnected: given a set $A$ with at least two points, one point is not in the quasi-component of the other and hence the two points can be separated by a clopen set. Hence the set $A$ is not connected.
This shows that the space is hereditarily disconnected.
On the other hand, if $X$ is locally compact and hereditarily disconnected, take $x\in X$
and let $U$ be an open set containing $x$.
By local compactness, find an open neighborhood $V\subseteq U$ of $x$ whose closure $\overline V$ is compact.
In a compact space, components and quasi-components coincide and hence the quasi-component of $x$ in $\overline V$ is $\{x\}$ (you don't need this if you are not interested in hereditary disconnected spaces but just totally disconnected ones). Using compactness again,
there are finitely many clopen subsets $C_1\dots,C_n$ of $\overline V$ such that
$x\in C_1\cap\dots\cap C_n\subseteq V$. The intersection of the $C_i$ is closed in $X$ since this intersection is compact.
It is open in $X$ since it is open in $V$ and $V$ is open in $X$.
This shows that the clopen subsets of $X$ form a basis.
Hence $X$ is zero-dimensional.
Edit: As suggested by Joseph Van Name, I include a proof that in a compact space the components coincide with the quasi-components.
Let $X$ be a compact space and $x\in X$. The component $C$
of $x$ is the union of all connected subsets of $X$ containing $x$. If $A\subseteq X$ is clopen and $x\in A$, then the component of $x$ is contained in $A$. It follows that the component of $x$ is contained in the quasi-component $Q$ of $x$.
In order to show that the component $C$ and the quasi-component $Q$ coincide,
it is now enough to show that $Q$ is connected.
Observe that $Q$ is closed in $X$ and thus compact.
Now suppose that $Q$ is not connected. Then there are nonempty,
relatively open subsets $A$ and $B$
of $Q$ such that $A\cap B=\emptyset$ and $A\cup B=Q$.
Note that $A$ and $B$ are relatively closed in $Q$ and hence compact.
Hence $A$ and $B$ are closed in $X$.
Two disjoint closed sets in a compact space can be separated by open subsets, i.e.,
there are disjoint open sets $U,V\subseteq X$ such that $A\subseteq U$ and $B\subseteq V$.
We have $$Q=\bigcap\{F\subseteq X:F\mbox{ is clopen and }x\in F\}$$
and thus
$$\bigcap\{F\subseteq X:F\mbox{ is clopen and }x\in F\}\cap(X\setminus(U\cup V))=\emptyset.$$
By compactness there are finitely many clopen sets $F_1,\dots,F_n$ containing $x$ such that
$$F_1\cap\dots\cap F_n\cap(X\setminus(U\cup V))=\emptyset.$$
Let $F=F_1\cap\dots\cap F_n$.
$F$ is clopen and we have $Q\subseteq F\subseteq U\cup V$.
We have
$$\overline{U\cap F}\subseteq\overline U\cap F=\overline U\cap(U\cup V)\cap F=U\cap F.$$
It follows that $U\cap F$ is clopen in $X$.
We may assume $x\in A$.
Since $B$ is nonempty, there is some $y\in B$.
But now $y\not\in U\cap F$. It follows that $y$ is not in the quasi-component of $x$,
a contradiction.
Best Answer
The set $\omega_1$ of countable ordinals with the order topology is a totally disconnected locally compact Hausdorff space which can not be written as a disjoint union of subsets that are both compact and open. This follows from the fact that the space is sequentially compact but not compact.