You can display both the monthly and yearly prices on the checkout page by adding the yearly price in "Upsells" in the monthly price edit page. So, it means that you have created both prices beforehand.
See the details here: https://docs.stripe.com/payments/checkout/upsells