In cognitive radios, the first and crucial task is to detect the spectrum holes or the presence of primary user by employing spectrum sensing. However, there exist two kinds of detection errors (i.e., miss-detection error and false-alarm error), which degrade the sensing performance severely. Aiming at minimizing the probability of total detection errors, based on the law of total probability we propose a novel target function (which also denotes the so-called comprehensive sensing performance metric) for optimization of sensing parameters. According to such established target function, we then apply the method of extremum seeking to develop the optimization of time-bandwidth product and sensing threshold jointly for local spectrum sensing with energy detection. Moreover, we further derive the closed-form expression of the optimal fusion rule for cooperative spectrum sensing by performing the discrete difference operation on the target function. Finally, the optimal area of joint parameters selection for local spectrum sensing and the effect of different detecting channel conditions on the optimization for cooperative spectrum sensing are evaluated numerically.