Worldwide installations of photovoltaics (PV) have increased rapidly due to national subsidies and decreasing prices. One important market segment is building-applied PV systems, for which the generated electricity can be self-consumed. Self-consumption is likely to become important both for the profitability and to facilitate integration of high shares of PV in the power system. The purpose of this doctoral thesis is to examine opportunities and challenges with distributed PV in the power system on four system levels: detached houses, communities, distribution systems and national level. This was done through literature studies and computer simulations. Previous research has shown a larger potential to increase the PV self-consumption in detached houses by using battery storage rather than shifting the household appliance loads. This thesis shows that, on the community level, the self-consumption increased more when sharing one large storage instead of individual storages in each house. On the distribution system level, PV power curtailment was identified as an effective solution to reduce the risk of overvoltage due to high PV penetration levels. However, the curtailment losses were high: up to 28% of the electricity production had to be curtailed in the studied distribution grid with a PV penetration of 100% of the yearly electricity consumption. However, the penetration of distributed PV on a national level is not likely to reach these levels. Around 12% of the Swedish households were estimated to have PV systems in 2040, although the uncertainties in the results were high, mainly related to the development of the electricity prices. The low profits from both PV but especially battery systems reduce future market shares. If residential batteries could also be used for primary frequency control, the profitability and thus the market shares for PV and battery systems could increase. The overall conclusions are that improved self-consumption can increase the profitability of PV systems and lower the negative impacts on grids with high PV penetration. Energy storage has a large potential to increase the self-consumption, but the profitability is still low for a storage that is only used to increase the self-consumption.