The gamma unit is used to irradiate a target within the brain. During such a treatment many parameters, including the number of shots, the coordinates, the collimator size and the weight associated with each shot, affect the amount of dose delivered to the target volume and to the surrounding normal tissues. Hence it is not easy to determine an appropriate set of these parameters by a trial and error method. For this reason, we present here an optimization method to determine mathematically those parameters. This method is composed of two steps: firstly, a quasi-Newton method is used to deal with the continuous variables such as position and weight of shots; the result obtained at the end of this step then serves as the initial configuration for the next step, in which a simulated annealing method is applied to optimize all the aforementioned parameters. Application of the proposed methods to two examples shows that our optimization algorithm runs in a satisfactory way.