Total energy calculations within the Density Functional Theory have been carried out in order to investigate the structural, electronic, and optical properties of un-doped and doped silicon nanostructures of different size and different surface terminations. In particular the effects induced by the creation of an electron-hole pair on the properties of hydrogenated silicon nanoclusters as a function of dimension are discussed in detail showing the strong interplay between the structural and optical properties of the system. The distortion induced on the structure by an electronic excitation of the cluster is analyzed and considered in the evaluation of the Stokes shift between absorption and emission energies. Besides we show how many-body effects crucially modify the absorption and emission spectra of the silicon nanocrystals. Starting from the hydrogenated clusters, different Si/O bonding at the cluster surface have been considered. We found that the presence of a Si--O--Si bridge bond originates significative excitonic luminescence features in the near-visible range. Concerning the doping, we consider B and P single- and co-doped Si nanoclusters. The neutral impurities formation energies are calculated and their dependence on the impurity position within the nanocrystal is discussed. In the case of co-doping the formation energy is strongly reduced, favoring this process with respect to the single doping. Moreover the band gap and the optical threshold are clearly red-shifted with respect to that of the pure crystals showing the possibility of an impurity based engineering of the absorption and luminescence properties of Si nanocrystals.