We carried out a deep subarcsecond BRI imaging of the two middle-aged pulsars to establish their properties in the optical range. Both pulsars are detected at >10sigma level in all bands. Geminga is for the first time reliably detected in the I band with a magnitude of 25.10+/-0.14. We also reanalyze archival ESO/NTT and HST broadband data and find that some published fluxes for Geminga were estimated inaccurately. The resulting dereddened broadband spectra in the near-IR-UV range are analyzed and compared with available data from the radio through gamma-rays. The dereddened spectra of both pulsars are remarkably similar to each other and show significant flux increases towards the far-UV and near-IR, and a wide flux excess in V-I bands. This suggests a multicomponent structure of the optical emission. The nonthermal power law component of the pulsar magnetospheric origin dominates in the most part of the optical range. For PSR B0656+14 it is compatible with a low energy extension of the power law tail seen in hard X-rays. For Geminga the respective extension overshoots by a factor of 100 the nonthermal optical flux, which has a less steep spectral slope than in X-rays. This implies a spectral break at a photon energy of about 1 keV. The flux increases towards the far-UV are compatible with contributions of the Rayleigh-Jeans parts of the blackbody components from whole surfaces of the neutron stars dominating in soft X-rays. The V-I excess, which is most significant for PSR B0656+14, suggests a third spectral component of still unidentified origin. Faint, a few arcseconds in size nebulae extended perpendicular to the proper motion directions of the pulsars, are seen around both objects in our deepest I band images. They can be optical counterparts of the bow-shock head of Geminga and of the tentative pulsar wind nebula of PSR B0656+14 observed in X-rays.
The paper has been accepted for publication in A&A and published in astro-ph/0511311.