The answer will depend on your criterion for "optimal" and on the true density $f$ that is to be estimated. A common criterion is the Mean Integrated Square Error
$$MISE = E\left( \int \left(f- \hat{f}\right)^2 dx\right)$$
where $\hat{f}$ is the kernel density estimate of $f$. One approach for finding an optimal $h$ is by means of "AMISE", which is an asymptotic epxansion (for small $h$) of MISE, and then analytically finding its minimum through $AMISE'(h) = 0$. This yields
$$h_{AMISE} = \left[\frac{\int K^2 dx}{n \int \left(f''\right)^2 dx \int x^2 K^2 dx}\right]^2$$
This is the startng points for most choices of $h$, e.g., by inserting a Gaussian for $f$, or by inserting the estimate $\hat{f}$ for $f$ and solving the resulting implicit equation for $h$ ("plug-in method").
For a gentle introdutcion into this topic, see
M. C. Jones, J. S. Marron, S. J. Sheather:
"A Brief Survey of Bandwidth Selection for Density Estimation.
Journal of the American Statistical Association
91,433, pp. 401-407 (1996)
or for a not so gentle, but more recent overview
SJ. Sheather: "Density Estimation."
Statistical Science 19,4, pp. 588–597 (2004)