First of all you made a slight mistake one of the equations is wrong
First equilibrium reaction,
$$\ce{Ag(aq)+ + e- <=> Ag(s)}$$
Writing the Nernst equation for this reaction
$$\ce{E_{Ag|Ag^+} = E_{Ag|Ag^+}^0 - \frac{RT}{F}ln\frac{\ce{[Ag]}}{\ce[Ag^+]}}$$
Second equilibrium reaction,
$$\ce{AgCl(s) + e- <=> Ag(s) + Cl-(aq)}$$
Writing the Nernst equation for the second reaction
$$\ce{E_{AgCl|Ag,Ag^+} = E_{AgCl|Ag,Ag^+}^0 - \frac{RT}{F}ln\frac{\ce{[Ag][Cl^-]}}{\ce[AgCl]}}$$
Since the activity of solids are considered to be 1
$$\ce{E_{Ag|Ag^+} = E_{Ag|Ag^+}^0 - \frac{RT}{F}ln\frac{\ce{1}}{\ce[Ag^+]}}$$
$$\ce{E_{AgCl|Ag,Ag^+} = E_{AgCl|Ag,Ag^+}^0 - \frac{RT}{F}ln\ce{[Cl^-]}}$$
When you short the wires of the two cells potential of the two cells equals
$$\ce{E_{Ag|Ag^+} = E_{AgCl|Ag,Ag^+}}$$
So
$$\ce{E_{Ag|Ag^+}^0 - \frac{RT}{F}ln\frac{\ce{1}}{\ce[Ag^+]}} = E_{AgCl|Ag,Ag^+}^0 - \frac{RT}{F}ln\ce{[Cl^-]}$$
Simplifying the math here gives your equation,
$$\ce{E_{AgCl|Ag,Ag^+}^0 = E_{Ag|Ag^+}^0 + \frac{RT}{F}ln([Ag^+][Cl^-])}$$
Since we know
$$\ce{AgCl(s) <=> Ag+(aq) + Cl-(aq)}$$
Overall reaction is this, is obtained by summing the two half cell reactions. (Need to connect the two electrodes to obtain this)(As one reduction and one oxidation doesn't matter since its in equilibrium)
$$\ce{K_{sp} = [Ag^+][Cl^-]}$$
The equation is,
$$\ce{E_{AgCl|Ag,Ag^+}^0 = E_{Ag|Ag^+}^0 + \frac{RT}{F}ln(K_{sp})}$$