This paper presents the results of a research activity in the framework of electric load management in buildings. The buildings are supposed to be smart; they are connected to the electric network but they are also equipped with PV plants for integration of the electric energy request with the relevant storage batteries. The idea behind is to use batteries of electric vehicles (present in the parking areas of the buildings) as supplementary storage systems. An algorithm is discussed, based on optimization techniques, that allows maximizing the number of electric appliances that can be fed in conditions of power limitation. The algorithm is purely numeric, and has been built with the idea to implement it in a software package that has been produced by the authors. Finally, a case study is presented which allows evaluating the reliability and the effectiveness of the proposed algorithms and of the software.