During millions of years of evolution, all creatures have found their ways of harvesting, storing and utilizing the energy coming from the sun. Plants use photosynthesis to convert carbon dioxide to glucose. With a low efficiency of only 3%, plants still capture enough energy to grow their roots, fruits and leaves. Animals regulate their body temperature by basking in the sun or seeking a shadow when needed. Human beings are the only species that is not satisfied with this natural share. With the exponential population growth and a gross domestic product per capita that doubles every fifty years, finding a clean, secure, and sustainable source of energy is inevitable. Photovoltaic solar cells together with a proper energy storage technology, like water splitting and a fuel cell to burn the stored hydrogen, can form the promising green cycle that solves the energy problem. Among different photovoltaic technologies, hybrid organic-inorganic solar cells, such as dye sensitized solar cells (DSSCs) or perovskite solar cells, are subject of active research due to their low-fabrication costs and easy production. In order to become commercially viable, these modules need to reach their theoretical Shockley-Queisser efficiency limit while acquiring enough durability and stability. In this context ab initio first-principles studies are of great help in order to give a fundamental insight of the chemistry and physics going on inside the cell. The main purpose of this dissertation is to make use of computational methods for a characterization of the fundamental processes in dye-sensitized and perovskite solar cells and the use of this knowledge for a rational design of solar cells with higher efficiencies. Starting from a systematic investigation of bio-inspired porphyrin-based dyes focused on their light harvesting properties, we were able to outline some key guidelines for designing efficient dye sensitizers. The outcome of this study was an efficient light harvester, which when integrated in an optimized device achieved the record-breaking 13% efficiency porphyrin- based dye sensitized solar cell. While having good sensitizers is a necessary condition for a high performance DSSC, it is often not enough. It is essential to know the interactions of different components of a DSSC and how they work together. For this reason, we performed atomistic molecular dynamics simulations of a comprehensive model of a DSSC consisting of dye molecules, TiO2 substrate, solvent and electrolyte. In particular, in these simulations, we studied the accessibility of oxidized electrolyte to the TiO2 substrate for different dye coverages and show that at medium to high coverage, peripheral alkyl groups of the dyes are highly efficient in shielding the TiO2 substrate from direct contact with the oxidized electrolyte preventing recombination. In a next chapter, and as a proof of principles study, we investigated the importance of solvation effects on the stability of a carbocation (as a prototype for the cationic dye species after electron injection). The last two parts of this thesis focus on perovskite solar cells where we show the origins of the highly tunable band gap and propose a simple model in terms of orbital overlap that can be used to rationalize and predict variations of the band gap as a function of crystal structure and chemical composition of the perovskite. Finally, we study the efficient carrier transport properties of these materials and show that there is a direct correlation between the efficiency of carrier transport and the band gap.