Castillo received a $15 million, two-year deal that includes a club option. The 30-year-old Castillo 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 $1.05 million, one-year contract. The 30-year-old Farquhar went 4-2 with a 4.20 ERA in 52 appearances last season with Tampa Bay and the White Sox.
• And left-hander Dario Alvarez and the Cubs agreed to a one-year contract.
The 28-year-old Dominican was 2-0 with a 2.76 ERA in 20 relief appearances with the Texas Rangers last season, striking out 17 in 16 1/3 innings.
Alvarez is 6-1 with a 5.06 ERA in 56 relief outings for the New York Mets (2014-15), Atlanta (2016) and Texas (2016-17).
The teams announced the agreements on Friday.