I am a big fan of the xparse package but I do not know how to use it to do what you want because it uses pairs of deliminators for (optional) arguments. EDIT Egreg's post Xparse's new e-type argument (replacement for k-type argument) describes how to use xparse to do this.
You can do this easily enough using \def and \@ifnextchar to test for a bracket -- the definitions need to be surrounded in \makeatletter...\makeatother because of the @ in \@ifnextchar.
More explicitly, I think that the following pair of macros do what you want:
\def\E_#1{\mathbf{E}_{#1}\@ifnextchar[{\Ebrac}{\relax}}
\def\Ebrac[#1]{#1}
The definition of \E says that it has one argument that follows an underscore. This macros then uses \@ifnextchar[ to call \Ebrac if the next character is a bracket.
Here is a full MWE:
\documentclass{article}
\makeatletter
\def\E_#1{\mathbf{E}_{#1}\@ifnextchar[{\Ebrac}{\relax}}
\def\Ebrac[#1]{#1}
\makeatother
\begin{document}
$\E_1, \E_\theta, \E_{\theta+1}$
$\E_1[X], \E_\theta[X], \E_{\theta+1}[X]$
\end{document}
This produces the output:

\newcommand\E{\mathbf{E}}and then use\E_\thetaand\E_\theta[X]. This said, I'd probably use\newcommand\bE{\mathbf{E}}. – Feb 06 '17 at 08:29xparsemanual. But use them with caution. – Schweinebacke Feb 06 '17 at 08:40