Is there a formal definition of opportunity costs, economic costs, and/or economic profits? [Edited to remove a mistake in a definition and some typos.]
According to various econ textbooks (e.g. this one), there is a fundamental distinction between economic profit and accounting profit:
(i) While accounting profit subtracts only explicit costs (out-of-pocket costs) from revenue,
(ii) economic profit subtracts opportunity costs, also known as economic costs, which consist of explicit and implicit costs. Here,
(iii) opportunity costs are generally defined as the &quot;value of the best foregone alternative&quot;. In the context of firms, &quot;value&quot; of course means profits.
(iv) Furthermore, when economists talk about &quot;costs&quot; and &quot;profits&quot;, they always mean economic costs and economic profits. For example, firms are assumed to maximize economic profits.
All the definitions I found were verbal and informal as above. Is there a formal definition of these concepts? Do they make sense at all? Since I didn't find anything in the literature (by a quick search, admittedly), I tried to formalize it myself for the firm context:
Let $X$ be a set of alternatives the firm can choose from, and let $z\in X$. Let's assume that alternative $z$ yields revenue $r(z)$ and generates explicit costs $c_e(z)$ for the firm. Accounting profit $\pi_a(z)$ is defined as revenue minus explicit costs, so $\pi_a(z)=r(z)-c_e(z)$. Economic profit $\pi_e(z)$ is then defined as accounting profit minus implicit costs $c_i(z)$, thus $\pi_e(z)=\pi_a(z)-c_i(z)=r(z)-(c_e(z)+c_i(z))=r(z)-c_o(z)$.
Opportunity costs of choosing $z$ are the value of the best foregone alternative, so $c_o(z)=\max_{k\in X,\,k\ne z}\pi(k)$.
Now, what is the &quot;profit&quot; $\pi(k)$ here? Economic profit or accounting profit? This might not be immediately obvious. Let's have a closer look.
Finite sets of alternatives
Assume for simplicity that there are only two alternatives, $X=\{x,y\}$, with $r(x)&gt;r(y)$.
(i) Let's try economic profits, so $\pi(k):=\pi_e(k)$:
Then $c_o(x)=\pi_e(y)$ and $c_o(y)=\pi_e(x)$.
Therefore $\pi_e(x)=r(x)-c_o(x)=r(x)-\pi_e(y)$. Now, analogously, $\pi_e(y)=r(y)-c_o(y)=r(y)-\pi_e(x)$. Substituting, $\pi_e(x)=r(x)-r(y)+\pi_e(x)$, implying $r(x)=r(y)$. This is a contradiction, so this approach makes no sense.
(ii) Let's interpret &quot;profit&quot; as accounting profit, i.e. $\pi(k):=\pi_a(k)$.
Then $c_o(x)=\pi_a(y)$ and $c_o(y)=\pi_a(x)$, so $\pi_e(x)=r(x)-c_o(x)=r(x)-\pi_a(y)=r(x)-r(y)+c_e(y)$. Similarily, $\pi_e(y)=r(y)-c_o(y)=r(y)-\pi_a(x)=r(y)-r(x)+c_e(x)$. This is at least not contradictory.
Infinite sets of alternatives
But there are rarely only two alternatives. Consider instead a standard quantity-setting monopolist. The set of alternatives is the set of quantity choices, so $X=\mathbb R^+$. Let's denote by $q^*$ the firm's optimal choice. Then the firm accrues accounting profits denoted by $\pi_a(q^*)=r(q^*)-c_e(q^*)$, where both $r$ and $c_e$ (and therefore $\pi_a$) are assumed to be continuous. What is the firm's economic profit $\pi_e(q^*)$ then?
Well, the firm's &quot;(accounting) profit from it's best foregone alternative&quot; is the accounting profit resulting from the smallest strictly positive deviation from $q^*$, which, unfortunately, doesn't exist. To the rescue, let's interpret the &quot;(accounting) profit from the best foregone alternative&quot; as the supremum (instead of the maximum) of the foregone accounting profits: $c_o(q^*)=\sup_{k\in X,\,k\ne q^*}\pi_a(k)$. This, however, is just $\pi_a(q^*)$. Then $\pi_e(q^*)=r(q^*)-\pi_a(q^*)=c_e(q^*)$.
Economic profit of a profit-maximizing monopolist being equal to its out-of-pocket costs? This seems not to make sense.
So do the concepts of economic profit and opportunity costs as defined in (i)-(iv) make sense at all? Or which of (i)-(iv) above is wrong? Or is the &quot;value&quot; of the best foregone alternative in the context of firm decisions neither economic nor accounting profit of the best foregone alternative? What else?
Economic profit
I think there are some problems with the formulation in your question, first you heavily focus on opportunity cost but note accounting profit does not even properly capture all revenue firm gets.
I will first focus on economic profit more broadly and at the end go back to opportunity cost.
Following Varian Microeconomic Analysis pp 24 (emphasis mine),

Economic profit is defined to be the difference between the revenue a firm receives and the costs that it incurs. It is important to understand that all costs must be included in the calculation of profit. …
Both revenues and costs of a firm depend on the actions taken by the firm. These actions may take many forms: actual production activities, purchases of factors, and purchases of advertising are all examples of actions undertaken by a firm. At a rather abstract level, we can imagine that a firm can engage in a large variety of actions such as these. We can write revenue as a function of the level of operations of some $n$ actions, $R(a_1,...,a_n)$, and costs as a function of these same $n$ activity levels, $C(a_1,...,a_n)$.

The above is already rigorous definition for economic profit, economic revenue and economic cost.
Note accounting operates under its own sets of rules. Accounting, is not econometrics. Point of accounting is not to accurately estimate or measure economic relationships. So what you are doing above, defining economic profit at simply accounting profit minus opportunity cost is somewhat misguided (it would only hold in an unrealistic special case where we assume accounting only missed opportunity cost but accounting misses so much more).
First, following Varian we can start with a set of occurring actions $a$ that create revenue and costs. However, when it comes to accounting, not all of these will be reported. For example l, consider selling goods without issuing receipt to avoid paying taxes, which will not get reported as accounting profit. The same holds for many costs other than opportunity cost. For example, consider how depreciation costs are treated by accountants. From purely economic perspective most assets definitely do not depreciate in linear fashion yet accounting allows firms to use linear depreciation for most assets regarding what the true depreciation cost each period is. So the accounting depreciation costs will too be different from economic depreciation cost. Or consider the fact that many countries allow small business to just in their accounting declare portion of their profit as cost without actually even proving they actually incurred these costs (this is done in some countries to ease administrative burden for sole traders and similar one person businesses).
Consequently, it makes more sense to rather define accounting profit in terms of economic profit and then work backwards by inverting those functions if you would want to get back to economic profit from accounting one.
Call $A=(a_1,...,a_n)$.  set of all economic actions that actually occur, and $R(A)$ would be economic revenue from those activities. Now apply some function $\rho$ which tells you based on $R(A)$ what actually accounting revenue is.
So accounting revenue $R_{acc}$ would be:
$$R_{acc}= \rho(R(A))$$
Similarly accounting cost $C_{acc}$, we will have actual economic cost firm incurs $C$ based on set of actions it takes $A$ and then we will have some function gamma that tells us what enters into accounting and what not so we would have that
$$C_{acc} = \gamma (C(A))$$
Finally the accounting profit would be difference between the above so:
$$\Pi_{acc} = \rho(R(A)) -\gamma (C(A))$$
Note what $\rho(.)$ and $\gamma(.)$ are will depend on local accounting regulations and laws. in some country government could declare that any firm has to put  always just 1000€ as their cost (yes it is unrealistic example but I am just showing it to prove a point) and in such case $\gamma(C(A))=1000$ regardless of anything that happens.
Whereas the true economic profit would just difference between economic revenues and economic costs:
$$\pi=R(A)-C(A)$$.
If you would want work your way back from accounting definitions then you could use inverse functions and economic profit calculated from accounting one would be:
$$\pi= \rho^{-1}-\gamma^{-1}$$.
Note the above does not really require definition of opportunity cost since here simply the function $C(A)$ is just some function where we assume that $C(A)$ assigns true economic cost to every action $a_1,…,a_n$, for standard profit optimization it’s completely okay to treat $C(.)$ as a black box and thus you will not really require separate definition of opportunity cost. As a matter of fact note in situation where there are no alternatives like having mana (from the biblical story where it could only be immediately consumed not stored or used for anything else) opportunity cost would not even be part of $C$ but still there would be distinction and disconnect between accounting and economic profit.
For example if we have $C(A)=c_1 a_1+c_2 a_2… c_n a_n$ and if we define $C$ as a function that always assigns true economic cost then you definition $c_1$ includes all economic costs including opportunity cost, but the economic profit, economic revenue and economic costs are still rigorously defined (even if the constituents of costs such as opportunity costs aren’t).
opportunity cost
Next tackling the opportunity cost separately (which can be later used to build function $C$), good places to start are Buchanan (1987) or Alchian (1968). The authors do not necessarily derive rigorous opportunity cost functions but give rigorous verbal definitions on which we can build.
For example, according by to Buchanan (1987) :

Opportunity cost is the anticipated value of 'that which might be' if choice were made differently. Note that it is not the value of 'that which might have been' without the qualifying reference to choice. In the absence of choice, it may be sometimes meaningful to discuss values of events that might have occurred but did not. It is not meaningful to define these values as opportunity costs, since the alternative scenario does not represent a lost or sacrificed opportunity. Once this basic relationship between choice and opportunity cost is acknowledged, several implications follow.


First, if choice is made among separately valued options, someone must do the choosing. That is to say, a chooser is required, a person who decides. From this the second implication emerges. The value placed on the option that is not chosen, the opportunity cost, must be that value that exists in the mind of the individual who chooses. It can find no other location. Hence, cost must be borne exclusively by the chooser; it can be shifted to no one else. A third necessary consequence is that opportunity cost must be subjective. It is within the mind of the chooser, and it cannot be objectified or measured by anyone external to the chooser. It cannot be readily translated into a resource, commodity, or money dimension. Fourth, opportunity cost exists only at the moment of decision when choice is made. It vanishes immediately thereafter. From this it follows that cost can never be realized; that which is rejected can never be enjoyed.

since the opportunity cost is the value of the next best alternative you can rigorously define as follows.
Suppose that for each action that actually was taken in the set $A=a_1,…,a_n$, there are alternative sets of alternative actions (e.g. each $a_i$, has some alternative $b_i$, $z_i$ and so on, and let’s assume that all the other alternatives are mutually exclusive with $a$. Well then opportunity cost of each action $a$ is just value of the next best alternative so if we have that:
$a_i\succ b_i \succ z_i … $
Then opportunity cost will simply be $V(b_1)$ where $V$ is simply just some function that assigns monetary value (or in consumer problem utility to $b_i$).
If you want to then put this value into profit function explicitly then simply the cost function will be some composite function given by $C(a_i, V(b_i))$ (note this is ultimately just function of $a_i$ because the next best alternative necessarily depends on what you choose as $a_i$, so in the end it’s just more complex way of writing $C(a_1))$
I think the above is rigorous even though it’s very simple (of course perhaps the notation I use could be made more precise).