Nowadays, the use of clean renewable energies is becoming increasingly necessary in order to preserve our environment and ensure our energy needs. Nevertheless, the integration of this type of energy still faces many challenges that must be overcome, especially the fluctuation and the storage. Researches for the optimization of these systems, particularly photovoltaic technologies, are getting widespread and diversified. The main purpose of our article is to optimize the battery sizing in a Stand Alone Photovoltaic System by identifying the most appropriate number of autonomy days. A case study in theregion of Errachidia in Morocco has been established and simulated to define the optimal number. In the others current researches, only a small importance has been attributed to the battery autonomy. The objective is generally to ensure a continuous presence of energy especially for isolated systems while this is not always optimal nor economical and does not necessarily guarantee a safe supply. However, an over dimensioning of the battery will lead to a consequent cost and a loss of energy. The results show that the number of days of autonomy must correspond to the minimum ratio linking the lack of energy to the surplus during a specific period.