Castillo received a two-year, $15 million deal that includes a club option. Castillo, 30, will make $7.25 million in each of the next two years, and the option is for $8 million with a $500,000 buyout.
Castillo, who broke into the majors with the crosstown Cubs in 2010, hit .282 with 20 homers and 53 RBIs in 96 games with Baltimore last season.
Farquhar avoided arbitration with his one-year, $1.05 million contract. Farquhar, 30, went 4-2 with a 4.20 ERA in 52 appearances last season with Tampa Bay and the White Sox.
The team announced the agreements on Friday.