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