Polymer-templated functional organic-inorganic nanocomposites for lithium ion batteries, capacitors and ferroelectric devices