In currently favoured scenarios, the Universe evolves from a highly homogeneous phase, emerging from the hot Big Bang, to the present-day state, which is characterised by a wealth of hierarchically organised structures, spanning several orders of magnitudes in size: galaxies, clusters of galaxies, superclusters, walls and filaments. Structures are formed via gravitational instability and grow hierarchically: the smallest ``haloes'' collapse first and then grow by accreting mass from other haloes or by merging with other similar structures. Gravitational and dynamical interactions, like mergers, accretions, tidal distortions and disruptions thus play a fundamental role in shaping galaxies and galaxy clusters. As a natural by-product of these interactions, stars, originally located within galaxies, are ejected into the space surrounding galaxies and into intracluster space, giving rise to diffuse stellar components. The study of these components can reveal important details of galaxy and cluster formation, and are therefore of great interest. Observations in this field are severely hampered by the extremely low surface brightness that has to be measured, corresponding to less than 1/1,000 of the typical surface brightness of the sky. So far, this has prevented observing large statistical samples of stellar haloes and intracluster stellar populations. The statistical characterisation of stellar haloes and of the intracluster light is the objective of this thesis. In order to do this, I have developed a new method in which a large number (approx. 1,000) of relatively shallow images of homogeneous objects are stacked to produce an extremely deep average image. Systematic effects that arise from contaminating sources and instrumental biases in the observation of individual objects are cancelled out by taking the average of many different observations and by adopting a conservative masking of the polluting sources. The large image database required for this technique has been provided by the Sloan Digital Sky Survey, the largest optical survey of the Universe ever undertaken, which will eventually cover approximately 10,000 square degrees of sky with 5-band photometry and spectroscopy. In the first part of the thesis I have studied the stellar haloes of disc galaxies. From the stacking of 1043 galaxies I have been able to infer the almost ubiquitous presence of this component around discs, thus demonstrating that haloes are essential ingredients of galaxy evolution. On average, stellar haloes have power-law profiles, consistent with those of the Milky Way and M31. Their shape is moderately flattened. The average halo colours hint at old and fairly metal-enriched stars. However, a puzzling emission excess in the redmost bands has been measured that cannot be explained by any stellar emission, but suggests the presence of ionised gas. These results have been confirmed by the analysis of a galaxy, which has been observed by the Hubble Space Telescope in its deepest exposure (the Ultra Deep Field). The second part of the thesis is devoted to a study of the intracluster light (ICL) from the stacking of a sample of 683 clusters of galaxies in the redshift range 0.2--0.3. The average contribution of the ICL to the total light of a cluster is 17.5 +- 2.0% within 700 kpc from the cluster centre. The ICL is significantly more centrally concentrated than the light in galaxies, consistent with the idea that the ICL is formed via tidal stripping and disruption of galaxies that plunge deep into the cluster potential. The colours of the ICL are consistent with those of the cluster galaxies, thus indicating that the intracluster stars stem from the same population as the stars in galaxies. The amount of ICL correlates more strongly with the luminosity of the central galaxy of the cluster than with cluster richness. Furthermore, the ICL aligns more strongly with the central galaxy than with the larger scale galaxy distribution in the cluster. This strongly suggest that the mechanism of formation of the ICL is strongly coupled with the process of growth of the cluster central galaxy.