In this paper we have studied the subcarrier and optimal power allocation strategy for OFDM-based cognitive radio (CR) networks. Firstly, in order to protect the primary user communication from the interference of the cognitive user transmissions in fading wireless channels, we design an opportunistic power control scheme to maximize the cognitive user capacity without degrading primary user's QoS. The mathematical optimization problem is formulated as maximizing the capacity of the secondary users under the interference constraint at the primary receiver and the Lagrange method is applied to obtain the optimal solution. Secondly, in order to limit the outage probability within primary user's tolerable range we analyze the outage probability of the primary user with respect to the interference power of the secondary user for imperfect CSI. Finally, in order to get the better tradeoff between fairness and system capacity in cognitive radio networks, we proposed an optimal algorithm of jointing subcarrier and power allocation scheme among multiple secondary users in OFDM-based cognitive radio networks. Simulation results demonstrate that our scheme can improve the capacity performance and efficiently guarantee the fairness of secondary users.