Both approaches actually co-exist.
I do have to know the preferences of consumer
Historically, aggregate goods were defined as those occurring in the utility function (whenever this happens). The main drawback of this approach was soon highlighted by Pu (1946, p.299): "If this criterion is strictly adhered to, one will find in most cases that either no aggregates can be found to fulfil this criterion, or, in the case where this criterion is satisfied by the manipulation of the construction of aggregates, the aggregates will become such monsters that they are completely void of any economic significance".
I do have to know the preferences of consumer
In contrast, other economists take for granted the given economic or statistical definition of the aggregate good or price, and construct aggregate utility (or production) functions as
$$ V(x_1,\textbf{x}_2) = \max_{x_2} \{ U(x_1,x_{21},x_{22},..,x_{2K}) : a(x_2)=\mathbf{x}_2 \}, $$
where the expression of the aggregator $a: \mathbb{R}^K \rightarrow \mathbb{R}$ is given, as well as its value $\mathbf{x}_2$.
For a contribution with this approach, see Blackorby and Schworm (1988). (Note that in general the optimal solution $x_2^*(\mathbf{x}_2)$ is not unique, but is a multivalued relationship.) With the aggregate quantity is $\mathbf{x}_2$, the corresponding price could be $\mathbf{p}_2 = \sum_k p_{2k}x_{2k} /\mathbf{x}_2$. (This is not fully compatible with your $P_y$ unless you divide it by $y$ to ensure that $P_yy=P_2x_2+P_3x_3.$ )
A third approach in this literature explicitly considers aggregation errors, and replaces all the elementary goods (or prices) by their aggregate counterparts and an error term: $x_{2k}=\textbf{x}_2\rho_{2k}$, so that the utility (production) function becomes:
$$ W(x_1,\textbf{x}_2;\rho) = U(x_1,x_{21},x_{22},\ldots,x_{2K})
= U(x_1,\textbf{x}_2\rho_{21},\ldots,\textbf{x}_2\rho_{2K}), $$
where the vector $\rho$ denotes the share of each elementary good in the aggregate:
$$ \rho = (x_{21},x_{22},\ldots,x_{2K}) / \textbf{x}_2. $$
Restrictions on the distributions of the unobserved $\rho$ are useful to achieve some interesting properties on the aggregate demand and supply functions. See for instance Lewbel (1996) for a contribution with this approach.
Blackorby, Charles, and William Schworm. “The Existence of Input and Output Aggregates in Aggregate Production Functions.” Econometrica, vol. 56, no. 3, 1988, pp. 613–43.
Lewbel, Arthur. “Aggregation Without Separability: A Generalized Composite Commodity Theorem.” The American Economic Review, vol. 86, no. 3, 1996, pp. 524–43.
Pu, Shou Shan. “A Note on Macroeconomics.” Econometrica, vol. 14, no. 4, 1946, pp. 299–302.