The aim of the paper is maximization of the Renewable Energy Sources (RES) generation in distribution network by its sizing and allocation, taking into account variable RES production. The objective function is annual energy generated by local RES calculated as a product of the power units rated power (control variable) and annual availability factor. In order to include technical constraints (such as power line capacity or nodal voltages), power flows are calculated. Loads are determinate by real daily demand profiles for residential and commercial customers. The optimization uses Mixed Integer-Linear Programming (MILP) and is solved by FICO® XPRESS optimization software. The method proposed allows for estimation power lines congestions and definition unutilized grid capacity. Consequently the utilization of network capacity is increased and more RES can be integrated. The method presented can be used by DSOs and Regulators as a guide for distribution code modification in terms of grid connection conditions.