Our first-principles calculations demonstrate that C(60-n)B(n) and C(60-m)N(m) can be engineered as the acceptors and donors, respectively, needed for molecular electronics by properly controlling the dopant number n and m in C60. We show that acceptor C48B12 and donor C48N12 are promising components for molecular rectifiers, carbon nanotube-based n-p-n (p-n-p) transistors, and p-n junctions.